-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement slice_strip
feature
#73414
Conversation
Does making the impls here heterogeneous (i.e. |
Unsure why I'm assigned, I'm not on the libs team. r? @Mark-Simulacrum |
I don't understand the question. impl<T> [T] {
fn strip_prefix<U>(&self, prefix: &[U]);
} |
Also, the Does pub fn starts_with(&self, needle: &[T]) -> bool |
r? @SimonSapin |
r? @dtolnay |
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.
Thanks! I am on board with this. It matches the method names on str
and it matches the starts/ends_with signatures on slice.
@bors r+ |
📌 Commit 560a996 has been approved by |
Implement `slice_strip` feature Tracking issue: rust-lang#73413
Implement `slice_strip` feature Tracking issue: rust-lang#73413
Implement `slice_strip` feature Tracking issue: rust-lang#73413
@bors r- |
src/libcore/slice/mod.rs
Outdated
/// | ||
/// ``` | ||
/// #![feature(slice_strip)] | ||
/// let v = &[10, 40, 30]; | ||
/// assert_eq!(v.strip_prefix(&[]), Some(v)); | ||
/// let v: &[u8] = &[]; | ||
/// assert_eq!(v.strip_prefix(&[]), Some(v)); | ||
/// ``` |
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.
Is this example needed?
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 removed it.
83f5819
to
6068504
Compare
src/libcore/slice/mod.rs
Outdated
/// This method returns the original slice if `prefix` is an empty slice | ||
/// or returns [`None`] if slice does not start with `prefix`. |
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 the wording of this was clearer in a previous revision. Slice not starting with prefix
is a scenario that is important to specify; this says what the meaning of Option in the return type is. Empty prefix
is a small clarification (not even an edge case, since the behavior falls out from the rest of the documentation). I think the emphasis in this paragraph is backward and not conducive to recognizing the part that is more important.
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 repharsed it. Could you take a look?
@bors r+ |
📌 Commit cd9d833 has been approved by |
…arth Rollup of 10 pull requests Successful merges: - rust-lang#73414 (Implement `slice_strip` feature) - rust-lang#73564 (linker: Create GNU_EH_FRAME header by default when producing ELFs) - rust-lang#73622 (Deny unsafe ops in unsafe fns in libcore) - rust-lang#73684 (add spans to injected coverage counters, extract with CoverageData query) - rust-lang#73812 (ast_pretty: Pass some token streams and trees by reference) - rust-lang#73853 (Add newline to rustc MultiSpan docs) - rust-lang#73883 (Compile rustdoc less often.) - rust-lang#73885 (Fix wasm32 being broken due to a NodeJS version bump) - rust-lang#73903 (Changes required for rustc/cargo to build for iOS targets) - rust-lang#73938 (Optimise fast path of checked_ops with `unlikely`) Failed merges: r? @ghost
Tracking issue: #73413