Skip to content

Commit 037a5b1

Browse files
committed
str: move as_mut_buf into OwnedStr, and make it self
1 parent 2dd3c44 commit 037a5b1

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/libstd/str.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,6 @@ pub trait StrSlice<'self> {
11921192
fn subslice_offset(&self, inner: &str) -> uint;
11931193
11941194
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T;
1195-
fn as_mut_buf<T>(&self, f: &fn(*mut u8, uint) -> T) -> T;
11961195
fn as_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T;
11971196
}
11981197
@@ -1965,23 +1964,6 @@ impl<'self> StrSlice<'self> for &'self str {
19651964
}
19661965
}
19671966
1968-
/**
1969-
* Work with the byte buffer and length of a slice.
1970-
*
1971-
* The given length is one byte longer than the 'official' indexable
1972-
* length of the string. This is to permit probing the byte past the
1973-
* indexable area for a null byte, as is the case in slices pointing
1974-
* to full strings, or suffixes of them.
1975-
*/
1976-
#[inline]
1977-
fn as_mut_buf<T>(&self, f: &fn(*mut u8, uint) -> T) -> T {
1978-
unsafe {
1979-
let v: *(*mut u8, uint) = cast::transmute(self);
1980-
let (buf, len) = *v;
1981-
f(buf, len)
1982-
}
1983-
}
1984-
19851967
/**
19861968
* Work with the byte buffer of a string as a null-terminated C string.
19871969
*
@@ -2056,6 +2038,18 @@ pub trait OwnedStr {
20562038
fn reserve_at_least(&mut self, n: uint);
20572039
fn capacity(&self) -> uint;
20582040
fn to_bytes_with_null(self) -> ~[u8];
2041+
2042+
/**
2043+
* Work with the mutable byte buffer and length of a slice.
2044+
*
2045+
* The given length is one byte longer than the 'official' indexable
2046+
* length of the string. This is to permit probing the byte past the
2047+
* indexable area for a null byte, as is the case in slices pointing
2048+
* to full strings, or suffixes of them.
2049+
*
2050+
* Make sure any mutations to this buffer keep this string valid UTF8.
2051+
*/
2052+
fn as_mut_buf<T>(&mut self, f: &fn(*mut u8, uint) -> T) -> T;
20592053
}
20602054
20612055
impl OwnedStr for ~str {
@@ -2246,6 +2240,12 @@ impl OwnedStr for ~str {
22462240
fn to_bytes_with_null(self) -> ~[u8] {
22472241
unsafe { ::cast::transmute(self) }
22482242
}
2243+
2244+
#[inline]
2245+
fn as_mut_buf<T>(&mut self, f: &fn(*mut u8, uint) -> T) -> T {
2246+
let v: &mut ~[u8] = unsafe { cast::transmute(self) };
2247+
v.as_mut_buf(f)
2248+
}
22492249
}
22502250
22512251
impl Clone for ~str {

0 commit comments

Comments
 (0)