-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor metadata to a more concise representation (#14) #15
base: main
Are you sure you want to change the base?
Conversation
The build failed, I will take a look later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
} | ||
|
||
fn convert_exif_date_time_to_chrono_date_time_fixed_offset( | ||
fn open_file(path: &Path, file_name: &String) -> Option<fs::File> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use Result
here as the return value because it already encodes the concept of an error case by design (same way you wouldn't return an Optional in Java instead of throwing an exception). By extension, I'd make read_metadata()
return a Result
.
Result
also allows using ?
which a nice way to chain function calls that return errors.
} | ||
|
||
fn convert_exif_date_time_to_chrono_date_time_fixed_offset( | ||
fn open_file(path: &Path, file_name: &String) -> Option<fs::File> { | ||
result_to_option(fs::File::open(path), "opening file ".to_owned() + file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently a more common way to format strings is format!()
.map(|file| get_exif_metadata(file, &file_name)) | ||
.flatten() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flat map is called and_then() in Rust. This would have been nice if we remembered from scala 😅
I wanted to play around with Rust and see if I can simplify a bit the extraction of the date time original and standardize the way we handle converting an error to an option.
What do you think?
Resolves #14