Skip to content

Implement cloned for Option<&mut T> #24203

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

Closed
wants to merge 1 commit into from

Conversation

Stebalien
Copy link
Contributor

Mirror Option<&T>.cloned().

Mirror `Option<&T>.cloned()`
@rust-highfive
Copy link
Contributor

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

This was originally intentionally left to just &T as it was a conservative option and it was unclear how many times you want to call .cloned() on Option<&mut T>. Unfortunately this also makes Option inconsistent with Iterator which also has a similar cloned method.

I'm curious, could you describe your use case for having an Option<&mut T> and then waning to clone it?

@alexcrichton alexcrichton assigned alexcrichton and unassigned pcwalton Apr 8, 2015
@Stebalien
Copy link
Contributor Author

A test case for a get_mut function. It isn't necessary but it just feels odd that this method is supported for references but not mutable references so I figured this might have been overlooked. What was the rational behind leaving it out?

@Stebalien
Copy link
Contributor Author

Closing because you're right. Any API that can return an Option<&mut T> should have a non-mut equivalent that returns an Option<&T> and users should be discouraged from requesting mutability/exclusive access when they don't need it.

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.

4 participants