std: remove the invalid NullTerminatedStr instance for &'static str.

A slice of a 'static str is still 'static, but doesn't necessarily
have the null terminator.
This commit is contained in:
Huon Wilson 2013-06-13 13:28:24 +10:00
parent da510bfb4a
commit abadece3ba
3 changed files with 22 additions and 17 deletions

View file

@ -1953,18 +1953,6 @@ impl NullTerminatedStr for @str {
slice
}
}
// static strings are the only slices guaranteed to a nul-terminator
impl NullTerminatedStr for &'static str {
/**
* Work with the byte buffer of a string as a byte slice.
*
* The byte slice does include the null terminator.
*/
#[inline]
fn as_bytes_with_null(&self) -> &'static [u8] {
unsafe { ::cast::transmute(*self) }
}
}
#[allow(missing_doc)]
pub trait OwnedStr {
@ -2925,10 +2913,6 @@ mod tests {
109, 0
];
assert_eq!("".as_bytes_with_null(), &[0]);
assert_eq!("abc".as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
assert_eq!("ศไทย中华Việt Nam".as_bytes_with_null(), v);
let s1 = @"";
let s2 = @"abc";
let s3 = @"ศไทย中华Việt Nam";