@@ -1981,35 +1981,6 @@ impl<'self> StrSlice<'self> for &'self str {
1981
1981
}
1982
1982
}
1983
1983
1984
- #[allow(missing_doc)]
1985
- pub trait NullTerminatedStr {
1986
- fn as_bytes_with_null<'a>(&'a self) -> &'a [u8];
1987
- }
1988
-
1989
- impl NullTerminatedStr for ~str {
1990
- /// Work with the byte buffer of a string as a byte slice.
1991
- ///
1992
- /// The byte slice does include the null terminator.
1993
- #[inline]
1994
- fn as_bytes_with_null<'a>(&'a self) -> &'a [u8] {
1995
- let ptr: &'a ~[u8] = unsafe { cast::transmute(self) };
1996
- let slice: &'a [u8] = *ptr;
1997
- slice
1998
- }
1999
- }
2000
-
2001
- impl NullTerminatedStr for @str {
2002
- /// Work with the byte buffer of a string as a byte slice.
2003
- ///
2004
- /// The byte slice does include the null terminator.
2005
- #[inline]
2006
- fn as_bytes_with_null<'a>(&'a self) -> &'a [u8] {
2007
- let ptr: &'a @[u8] = unsafe { cast::transmute(self) };
2008
- let slice: &'a [u8] = *ptr;
2009
- slice
2010
- }
2011
- }
2012
-
2013
1984
#[allow(missing_doc)]
2014
1985
pub trait OwnedStr {
2015
1986
fn push_str_no_overallocate(&mut self, rhs: &str);
@@ -2979,30 +2950,6 @@ mod tests {
2979
2950
assert_eq!(" ศไทย中华Việt Nam ".as_bytes(), v);
2980
2951
}
2981
2952
2982
- #[test]
2983
- fn test_as_bytes_with_null() {
2984
- // has null
2985
- let v = [
2986
- 224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228,
2987
- 184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97,
2988
- 109, 0
2989
- ];
2990
-
2991
- let s1 = @" ";
2992
- let s2 = @" abc";
2993
- let s3 = @" ศไทย中华Việt Nam ";
2994
- assert_eq!(s1.as_bytes_with_null(), &[0]);
2995
- assert_eq!(s2.as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
2996
- assert_eq!(s3.as_bytes_with_null(), v);
2997
-
2998
- let s1 = ~" ";
2999
- let s2 = ~" abc";
3000
- let s3 = ~" ศไทย中华Việt Nam ";
3001
- assert_eq!(s1.as_bytes_with_null(), &[0]);
3002
- assert_eq!(s2.as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
3003
- assert_eq!(s3.as_bytes_with_null(), v);
3004
- }
3005
-
3006
2953
#[test]
3007
2954
fn test_to_bytes_with_null() {
3008
2955
let s = ~" ศไทย中华Việt Nam ";
@@ -3024,7 +2971,7 @@ mod tests {
3024
2971
// Don't double free. (I'm not sure if this exercises the
3025
2972
// original problem code path anymore.)
3026
2973
let s = ~" ";
3027
- let _bytes = s.as_bytes_with_null ();
2974
+ let _bytes = s.as_bytes ();
3028
2975
fail!();
3029
2976
}
3030
2977
0 commit comments