Skip to content

Commit dca9ff9

Browse files
committed
std: remove str::NullTerminatedStr
1 parent fd293df commit dca9ff9

File tree

3 files changed

+2
-76
lines changed

3 files changed

+2
-76
lines changed

src/libstd/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub use path::PosixPath;
6363
pub use path::WindowsPath;
6464
pub use ptr::RawPtr;
6565
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, ToBytesConsume};
66-
pub use str::{Str, StrVector, StrSlice, OwnedStr, NullTerminatedStr};
66+
pub use str::{Str, StrVector, StrSlice, OwnedStr};
6767
pub use from_str::{FromStr};
6868
pub use to_bytes::IterBytes;
6969
pub use to_str::{ToStr, ToStrConsume};

src/libstd/str.rs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,35 +1981,6 @@ impl<'self> StrSlice<'self> for &'self str {
19811981
}
19821982
}
19831983
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-
20131984
#[allow(missing_doc)]
20141985
pub trait OwnedStr {
20151986
fn push_str_no_overallocate(&mut self, rhs: &str);
@@ -2979,30 +2950,6 @@ mod tests {
29792950
assert_eq!("ศไทย中华Việt Nam".as_bytes(), v);
29802951
}
29812952
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-
30062953
#[test]
30072954
fn test_to_bytes_with_null() {
30082955
let s = ~"ศไทย中华Việt Nam";
@@ -3024,7 +2971,7 @@ mod tests {
30242971
// Don't double free. (I'm not sure if this exercises the
30252972
// original problem code path anymore.)
30262973
let s = ~"";
3027-
let _bytes = s.as_bytes_with_null();
2974+
let _bytes = s.as_bytes();
30282975
fail!();
30292976
}
30302977

src/test/compile-fail/static-slice-not-null-terminated.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)