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

Document std::borrow with examples #23669

Merged
merged 1 commit into from
Apr 1, 2015

Conversation

steveklabnik
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

r? @pcwalton

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

@alexcrichton
Copy link
Member

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 Borrow and BorrowMut in generic contexts?

@steveklabnik
Copy link
Member Author

@alexcrichton ahhh yes, i will do that then

@steveklabnik
Copy link
Member Author

So, in the intervening time, I get errors when trying to run rustdoc on libcollections:

$ rustdoc --test src/libcollections/lib.rs 
src/libcollections/btree/map.rs:1392:32: 1392:58 error: slice pattern syntax is experimental
src/libcollections/btree/map.rs:1392                         if let [ref $($mutability)* edge] = slice.edges {
                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
src/libcollections/btree/map.rs:1342:1: 1470:2 note: in expansion of range_impl!
src/libcollections/btree/map.rs:1496:9: 1497:6 note: expansion site
src/libcollections/btree/map.rs:1392:58: 1392:58 help: add #![feature(slice_patterns)] to the crate attributes to enable
src/libcollections/btree/map.rs:1342:1: 1470:2 note: in expansion of range_impl!
src/libcollections/btree/map.rs:1496:9: 1497:6 note: expansion site
src/libcollections/btree/map.rs:1392:32: 1392:58 error: slice pattern syntax is experimental
src/libcollections/btree/map.rs:1392                         if let [ref $($mutability)* edge] = slice.edges {
                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
src/libcollections/btree/map.rs:1342:1: 1470:2 note: in expansion of range_impl!
src/libcollections/btree/map.rs:1523:9: 1525:6 note: expansion site
src/libcollections/btree/map.rs:1392:58: 1392:58 help: add #![feature(slice_patterns)] to the crate attributes to enable
src/libcollections/btree/map.rs:1342:1: 1470:2 note: in expansion of range_impl!
src/libcollections/btree/map.rs:1523:9: 1525:6 note: expansion site
error: aborting due to 2 previous errors
thread '<unnamed>' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:152
thread '<main>' panicked at 'child thread None panicked', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/mod.rs:775

Unsure what's up with that. The build shouldn't be failing now, should it?

@steveklabnik
Copy link
Member Author

Nevermind, i needed to rebase, that's all

@steveklabnik
Copy link
Member Author

@alexcrichton updated, r?

/// ```
/// use std::borrow::Cow;
///
/// let mut cow: Cow<&str> = Cow::Owned("Hello");
Copy link
Member

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?

Copy link
Member Author

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.

@steveklabnik
Copy link
Member Author

@alexcrichton updated, thanks :D

@alexcrichton
Copy link
Member

@bors: r+ edc096d

@alexcrichton
Copy link
Member

@bors: rollup

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 31, 2015
@bors bors merged commit edc096d into rust-lang:master Apr 1, 2015
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.

5 participants