Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gmarouli
Copy link
Collaborator

@gmarouli gmarouli commented Jul 4, 2022

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

@gmarouli
Copy link
Collaborator Author

gmarouli commented Jul 4, 2022

The build failed, I will take a look later

Copy link
Owner

@simisimis simisimis left a 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> {
Copy link
Collaborator

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)
Copy link
Collaborator

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!()

Comment on lines +132 to +133
.map(|file| get_exif_metadata(file, &file_name))
.flatten()
Copy link
Collaborator

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 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor extracting date taken to be more concise
3 participants