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

Change feedback to return Option<&Feedback> #73

Merged
merged 1 commit into from
May 23, 2024
Merged

Change feedback to return Option<&Feedback> #73

merged 1 commit into from
May 23, 2024

Conversation

Grafcube
Copy link
Contributor

@Grafcube Grafcube commented Oct 24, 2023

This PR changes the Entropy::feedback() function to return Option<&Feedback> instead of &Option<Feedback>. This makes the API significantly easier to use as Option<&...> implements Copy and it's also more accurate, semantically.

Say I want to call map on the return value of the function:

let feedback = entropy.feedback().map(|f| f.to_owned());

This results in an error with &Option<Feedback>:

error[E0507]: cannot move out of a shared reference
    --> ui/src/routes/auth.rs:233:38
     |
233  |                         feedback.set(entropy.feedback().map(|f| f.to_owned()));
     |                                      ^^^^^^^^^^^^^^^^^^ --------------------- value moved due to this method call
     |                                      |
     |                                      help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
     |                                      move occurs because value has type `std::option::Option<Feedback>`, which does not implement the `Copy` trait
     |
note: `std::option::Option::<T>::map` takes ownership of the receiver `self`, which moves value

Using Option<&Feedback> makes this compile without any errors.

@Grafcube
Copy link
Contributor Author

@shssoichiro does this PR look okay?

@shssoichiro
Copy link
Owner

Sorry for not looking at this sooner. Yes, this looks good. Thanks.

@shssoichiro shssoichiro merged commit e361e3d into shssoichiro:master May 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants