Fixup String::split_off documentation
1. Clarify that `String::split_off` returns one string and modifies self in-place. The documentation implied that it returns two new strings. 2. Make the documentation mirror `Vec::split_off`.
This commit is contained in:
parent
668864d9ed
commit
eec9e988e1
@ -1250,17 +1250,17 @@ impl String {
|
|||||||
self.len() == 0
|
self.len() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Divide one string into two at an index.
|
/// Splits the string into two at the given index.
|
||||||
///
|
///
|
||||||
/// The argument, `mid`, should be a byte offset from the start of the string. It must also
|
/// Returns a newly allocated `String`. `self` contains bytes `[0, at)`, and
|
||||||
/// be on the boundary of a UTF-8 code point.
|
/// the returned `String` contains bytes `[at, len)`. `at` must be on the
|
||||||
|
/// boundary of a UTF-8 code point.
|
||||||
///
|
///
|
||||||
/// The two strings returned go from the start of the string to `mid`, and from `mid` to the end
|
/// Note that the capacity of `self` does not change.
|
||||||
/// of the string.
|
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if `mid` is not on a `UTF-8` code point boundary, or if it is beyond the last
|
/// Panics if `at` is not on a `UTF-8` code point boundary, or if it is beyond the last
|
||||||
/// code point of the string.
|
/// code point of the string.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
@ -1275,9 +1275,9 @@ impl String {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "string_split_off", since = "1.16.0")]
|
#[stable(feature = "string_split_off", since = "1.16.0")]
|
||||||
pub fn split_off(&mut self, mid: usize) -> String {
|
pub fn split_off(&mut self, at: usize) -> String {
|
||||||
assert!(self.is_char_boundary(mid));
|
assert!(self.is_char_boundary(at));
|
||||||
let other = self.vec.split_off(mid);
|
let other = self.vec.split_off(at);
|
||||||
unsafe { String::from_utf8_unchecked(other) }
|
unsafe { String::from_utf8_unchecked(other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user