Skip to content

Refactor metadata to a more concise representation (#14)#15

Open
gmarouli wants to merge 3 commits intomainfrom
refactor-metadata
Open

Refactor metadata to a more concise representation (#14)#15
gmarouli wants to merge 3 commits intomainfrom
refactor-metadata

Conversation

@gmarouli
Copy link
Copy Markdown
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
Copy Markdown
Collaborator Author

gmarouli commented Jul 4, 2022

The build failed, I will take a look later

Copy link
Copy Markdown
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!

Comment thread src/metadata.rs
}

fn convert_exif_date_time_to_chrono_date_time_fixed_offset(
fn open_file(path: &Path, file_name: &String) -> Option<fs::File> {
Copy link
Copy Markdown
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.

Comment thread src/metadata.rs

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
Copy Markdown
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 thread src/metadata.rs
Comment on lines +132 to +133
.map(|file| get_exif_metadata(file, &file_name))
.flatten()
Copy link
Copy Markdown
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