core_str::StrExt::split_at(self, mid)
}
+ /// Divide one mutable string slice into two at an index.
+ #[inline]
+ pub fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
+ core_str::StrExt::split_at_mut(self, mid)
+ }
+
/// An iterator over the codepoints of `self`.
///
/// # Examples
assert_eq!(b, "");
}
+#[test]
+fn test_split_at_mut() {
+ use std::ascii::AsciiExt;
+ let mut s = "Hello World".to_string();
+ {
+ let (a, b) = s.split_at_mut(5);
+ a.make_ascii_uppercase();
+ b.make_ascii_lowercase();
+ }
+ assert_eq!(s, "HELLO world");
+}
+
#[test]
#[should_panic]
fn test_split_at_boundscheck() {
where P::Searcher: ReverseSearcher<'a>;
fn find_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize>;
fn split_at(&self, mid: usize) -> (&str, &str);
+ fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
fn slice_shift_char<'a>(&'a self) -> Option<(char, &'a str)>;
fn subslice_offset(&self, inner: &str) -> usize;
fn as_ptr(&self) -> *const u8;
}
}
+ fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
+ // is_char_boundary checks that the index is in [0, .len()]
+ if self.is_char_boundary(mid) {
+ let len = self.len();
+ unsafe {
+ let self2: &mut str = mem::transmute_copy(&self);
+ (self.slice_mut_unchecked(0, mid),
+ self2.slice_mut_unchecked(mid, len))
+ }
+ } else {
+ slice_error_fail(self, 0, mid)
+ }
+ }
+
#[inline]
fn slice_shift_char(&self) -> Option<(char, &str)> {
if self.is_empty() {