about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2013-07-03 20:02:09 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2013-08-04 13:32:41 -0700
commitdca9ff9a13b0ca04160828413e4550225fb1e04f (patch)
treeedf38cfa0066b3eedce2f9975ef1f9da80f7ba12 /src
parentfd293dfb0f97962697a967b2fae12b54225d7a11 (diff)
downloadrust-dca9ff9a13b0ca04160828413e4550225fb1e04f.tar.gz
rust-dca9ff9a13b0ca04160828413e4550225fb1e04f.zip
std: remove str::NullTerminatedStr
Diffstat (limited to 'src')
-rw-r--r--src/libstd/prelude.rs2
-rw-r--r--src/libstd/str.rs55
-rw-r--r--src/test/compile-fail/static-slice-not-null-terminated.rs21
3 files changed, 2 insertions, 76 deletions
diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs
index 517bc4a441a..7e21504c1d2 100644
--- a/src/libstd/prelude.rs
+++ b/src/libstd/prelude.rs
@@ -63,7 +63,7 @@ pub use path::PosixPath;
 pub use path::WindowsPath;
 pub use ptr::RawPtr;
 pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, ToBytesConsume};
-pub use str::{Str, StrVector, StrSlice, OwnedStr, NullTerminatedStr};
+pub use str::{Str, StrVector, StrSlice, OwnedStr};
 pub use from_str::{FromStr};
 pub use to_bytes::IterBytes;
 pub use to_str::{ToStr, ToStrConsume};
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index c936c1e25db..2a24351fff4 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -1982,35 +1982,6 @@ impl<'self> StrSlice<'self> for &'self str {
 }
 
 #[allow(missing_doc)]
-pub trait NullTerminatedStr {
-    fn as_bytes_with_null<'a>(&'a self) -> &'a [u8];
-}
-
-impl NullTerminatedStr for ~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<'a>(&'a self) -> &'a [u8] {
-        let ptr: &'a ~[u8] = unsafe { cast::transmute(self) };
-        let slice: &'a [u8] = *ptr;
-        slice
-    }
-}
-
-impl NullTerminatedStr for @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<'a>(&'a self) -> &'a [u8] {
-        let ptr: &'a @[u8] = unsafe { cast::transmute(self) };
-        let slice: &'a [u8] = *ptr;
-        slice
-    }
-}
-
-#[allow(missing_doc)]
 pub trait OwnedStr {
     fn push_str_no_overallocate(&mut self, rhs: &str);
     fn push_str(&mut self, rhs: &str);
@@ -2980,30 +2951,6 @@ mod tests {
     }
 
     #[test]
-    fn test_as_bytes_with_null() {
-        // has null
-        let v = [
-            224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228,
-            184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97,
-            109, 0
-        ];
-
-        let s1 = @"";
-        let s2 = @"abc";
-        let s3 = @"ศไทย中华Việt Nam";
-        assert_eq!(s1.as_bytes_with_null(), &[0]);
-        assert_eq!(s2.as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
-        assert_eq!(s3.as_bytes_with_null(), v);
-
-        let s1 = ~"";
-        let s2 = ~"abc";
-        let s3 = ~"ศไทย中华Việt Nam";
-        assert_eq!(s1.as_bytes_with_null(), &[0]);
-        assert_eq!(s2.as_bytes_with_null(), &['a' as u8, 'b' as u8, 'c' as u8, 0]);
-        assert_eq!(s3.as_bytes_with_null(), v);
-    }
-
-    #[test]
     fn test_to_bytes_with_null() {
         let s = ~"ศไทย中华Việt Nam";
         let v = ~[
@@ -3024,7 +2971,7 @@ mod tests {
         // Don't double free. (I'm not sure if this exercises the
         // original problem code path anymore.)
         let s = ~"";
-        let _bytes = s.as_bytes_with_null();
+        let _bytes = s.as_bytes();
         fail!();
     }
 
diff --git a/src/test/compile-fail/static-slice-not-null-terminated.rs b/src/test/compile-fail/static-slice-not-null-terminated.rs
deleted file mode 100644
index 3cfaa57d540..00000000000
--- a/src/test/compile-fail/static-slice-not-null-terminated.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn main() {
-    let _ = (~"foo").as_bytes_with_null();
-    let _ = (@"foo").as_bytes_with_null();
-
-    // a plain static slice is null terminated, but such a slice can
-    // be sliced shorter (i.e. become non-null terminated) and still
-    // have the static lifetime
-    let foo: &'static str = "foo";
-    let _ = foo.as_bytes_with_null();
-     //~^ ERROR does not implement any method in scope named `as_bytes_with_null`
-}