-
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
Add Cow::is_borrowed and Cow::is_owned #65144
Conversation
r? @TimNN (rust_highfive has picked a reviewer for you, use r? to override) |
f3cace4
to
2b767e4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
You can run the tests locally i.e. with |
src/liballoc/borrow.rs
Outdated
/// #![feature(cow_is_borrowed)] | ||
/// use std::borrow::Cow; | ||
/// | ||
/// let mut cow = Cow::Borrowed("moo"); |
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.
let cow = Cow::Borrowed("moo");
src/liballoc/borrow.rs
Outdated
/// let mut cow = Cow::Borrowed("moo"); | ||
/// assert!(cow.is_borrowed()); | ||
/// | ||
/// let mut bull: Cow<'_, str> = Cow::Owned("...moo?".to_string()); |
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.
let bull: Cow<str> = Cow::Owned("...moo?".to_string());
src/liballoc/borrow.rs
Outdated
match *self { | ||
Borrowed(_) => false, | ||
Owned(_) => true, | ||
} |
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.
Why not: !self.is_borrowed()
? (see is_some
/is_none
, is_ok
/is_err
)
src/liballoc/borrow.rs
Outdated
/// #![feature(cow_is_borrowed)] | ||
/// use std::borrow::Cow; | ||
/// | ||
/// let mut cow: Cow<'_, str> = Cow::Owned("moo".to_string()); |
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.
let cow: Cow<str> = Cow::Owned("moo".to_string());
src/liballoc/borrow.rs
Outdated
/// let mut cow: Cow<'_, str> = Cow::Owned("moo".to_string()); | ||
/// assert!(cow.is_owned()); | ||
/// | ||
/// let mut bull = Cow::Borrowed("...moo?".to_string()); |
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.
let bull = Cow::Borrowed("...moo?");
same as above, but if you want to use a String
instead do:
let bull: Cow<str> = Cow::Borrowed("...moo?".to_string());
That would make too much sense |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@clarfon you don't like the suggestion: you need to add Line 125 in b5bd31e
|
Thank you for the comment about the feature flag. I was just convinced that intra-doc links were broken again >< |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ping from triage. @TimNN can you please review this PR? Thanks. |
Removed the links on |
@ProgrammaticNajel TimNN seems to be not available. Can you reassign it please? |
r? @sfackler |
@bors r+ |
📌 Commit eeb549b has been approved by |
Add Cow::is_borrowed and Cow::is_owned Implements rust-lang#65143.
Add Cow::is_borrowed and Cow::is_owned Implements rust-lang#65143.
Rollup of 12 pull requests Successful merges: - #64178 (More Clippy fixes for alloc, core and std) - #65144 (Add Cow::is_borrowed and Cow::is_owned) - #65193 (Lockless LintStore) - #65479 (Add the `matches!( $expr, $pat ) -> bool` macro) - #65518 (Avoid ICE when checking `Destination` of `break` inside a closure) - #65583 (rustc_metadata: use a table for super_predicates, fn_sig, impl_trait_ref.) - #65641 (Derive `Rustc{En,De}codable` for `TokenStream`.) - #65648 (Eliminate `intersect_opt`.) - #65657 (Remove `InternedString`) - #65691 (Update E0659 error code long explanation to 2018 edition) - #65696 (Fix an issue with const inference variables sticking around under Chalk + NLL) - #65704 (relax ExactSizeIterator bound on write_bytes) Failed merges: r? @ghost
Implements #65143.