-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Document std::borrow with examples #23669
Conversation
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
With the borrow module I believe the primary use case is actually through generics, not through direct usage for the traits. Perhaps the examples could show off some examples of using |
@alexcrichton ahhh yes, i will do that then |
So, in the intervening time, I get errors when trying to run
Unsure what's up with that. The build shouldn't be failing now, should it? |
Nevermind, i needed to rebase, that's all |
f9b3dd0
to
30baca0
Compare
@alexcrichton updated, r? |
/// ``` | ||
/// use std::borrow::Cow; | ||
/// | ||
/// let mut cow: Cow<&str> = Cow::Owned("Hello"); |
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 that this example may want to be redone a bit, the Owned
variant is meant to represent something like String
, and you probably don't want to call to_mut
on Cow<str>
because that will give you the type &mut str
which isn't super useful.
Perhaps this could be Cow<[_]>
where the owned variant is vec![1, 2, 3]
and then you call .to_mut()
to modify one of the elements and then assert that the cow
is equal to a slice?
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.
Sounds good. This was an awkward one to even write.
30baca0
to
edc096d
Compare
@alexcrichton updated, thanks :D |
@bors: rollup |
No description provided.