@@ -1192,7 +1192,6 @@ pub trait StrSlice<'self> {
1192
1192
fn subslice_offset(&self, inner: &str) -> uint;
1193
1193
1194
1194
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;
1196
1195
fn as_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T;
1197
1196
}
1198
1197
@@ -1965,23 +1964,6 @@ impl<'self> StrSlice<'self> for &'self str {
1965
1964
}
1966
1965
}
1967
1966
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
-
1985
1967
/**
1986
1968
* Work with the byte buffer of a string as a null-terminated C string.
1987
1969
*
@@ -2056,6 +2038,18 @@ pub trait OwnedStr {
2056
2038
fn reserve_at_least(&mut self, n: uint);
2057
2039
fn capacity(&self) -> uint;
2058
2040
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;
2059
2053
}
2060
2054
2061
2055
impl OwnedStr for ~str {
@@ -2246,6 +2240,12 @@ impl OwnedStr for ~str {
2246
2240
fn to_bytes_with_null(self) -> ~[u8] {
2247
2241
unsafe { ::cast::transmute(self) }
2248
2242
}
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
+ }
2249
2249
}
2250
2250
2251
2251
impl Clone for ~str {
0 commit comments