]> git.lizzy.rs Git - rust.git/commitdiff
Remove OwnedStr trait
authorAdolfo OchagavĂ­a <aochagavia92@gmail.com>
Sat, 19 Jul 2014 09:34:51 +0000 (11:34 +0200)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 24 Jul 2014 14:25:43 +0000 (07:25 -0700)
This trait was only implemented by `String`. It provided the methods
`into_bytes` and `append`, both of which **are already implemented as normal
methods** of `String` (not as trait methods). This change improves the
consistency of strings.

This shouldn't break any code, except if somebody has implemented
`OwnedStr` for a user-defined type.

src/libcollections/str.rs
src/libstd/ascii.rs
src/libstd/os.rs
src/libstd/prelude.rs

index c0e903677de354a2155fc23e1d82105e52910c09..ae1fb87ef7f9600e1e04cd1ac6fa3fc9c703607b 100644 (file)
@@ -603,11 +603,6 @@ pub unsafe fn from_byte(u: u8) -> String {
         from_utf8_owned(vec![u])
     }
 
-    /// Sets the length of a string
-    ///
-    /// This will explicitly set the size of the string, without actually
-    /// modifying its buffers, so it is up to the caller to ensure that
-    /// the string is actually the specified size.
     #[test]
     fn test_from_buf_len() {
         use slice::ImmutableVector;
@@ -785,30 +780,6 @@ fn into_string(self) -> String {
     }
 }
 
-/// Methods for owned strings
-pub trait OwnedStr {
-    /// Consumes the string, returning the underlying byte buffer.
-    ///
-    /// The buffer does not have a null terminator.
-    fn into_bytes(self) -> Vec<u8>;
-
-    /// Pushes the given string onto this string, returning the concatenation of the two strings.
-    fn append(self, rhs: &str) -> String;
-}
-
-impl OwnedStr for String {
-    #[inline]
-    fn into_bytes(self) -> Vec<u8> {
-        unsafe { mem::transmute(self) }
-    }
-
-    #[inline]
-    fn append(mut self, rhs: &str) -> String {
-        self.push_str(rhs);
-        self
-    }
-}
-
 #[cfg(test)]
 mod tests {
     use std::iter::AdditiveIterator;
index 02cb5dd245b7cbdf3b852f43e9d0be60523899ed..bcc0761d92a3a75a90861183df084847d9d47c8c 100644 (file)
@@ -20,7 +20,7 @@
 use mem;
 use option::{Option, Some, None};
 use slice::{ImmutableVector, MutableVector, Vector};
-use str::{OwnedStr, Str, StrAllocating, StrSlice};
+use str::{Str, StrAllocating, StrSlice};
 use string::String;
 use to_string::IntoStr;
 use vec::Vec;
index f71f1d22d009d0f95e07d1d15f7c4576c542a6ac..ca76be40cb59421c2c93f531324ee31941d80593 100644 (file)
@@ -56,8 +56,6 @@
 use c_str::ToCStr;
 #[cfg(unix)]
 use libc::c_char;
-#[cfg(windows)]
-use str::OwnedStr;
 
 /// Get the number of cores available
 pub fn num_cpus() -> uint {
@@ -708,8 +706,6 @@ fn load_self() -> Option<Vec<u8>> {
 
     #[cfg(windows)]
     fn load_self() -> Option<Vec<u8>> {
-        use str::OwnedStr;
-
         unsafe {
             use os::win32::fill_utf16_buf_and_decode;
             fill_utf16_buf_and_decode(|buf, sz| {
index 0ce7497cf300e7ef3776cb2603ef963fa59e57ed..96d5c0785f47774650696b43ad0b9f9ef2816983 100644 (file)
@@ -76,7 +76,7 @@
 #[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath};
 #[doc(no_inline)] pub use ptr::RawPtr;
 #[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek};
-#[doc(no_inline)] pub use str::{Str, StrVector, StrSlice, OwnedStr};
+#[doc(no_inline)] pub use str::{Str, StrVector, StrSlice};
 #[doc(no_inline)] pub use str::{IntoMaybeOwned, StrAllocating, UnicodeStrSlice};
 #[doc(no_inline)] pub use to_string::{ToString, IntoStr};
 #[doc(no_inline)] pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};