Skip to content

Commit

Permalink
Remove OwnedStr trait
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aochagavia authored and alexcrichton committed Jul 24, 2014
1 parent 482c776 commit ba707fb
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 35 deletions.
29 changes: 0 additions & 29 deletions src/libcollections/str.rs
Expand Up @@ -603,11 +603,6 @@ pub mod raw {
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;
Expand Down Expand Up @@ -785,30 +780,6 @@ impl<'a> StrAllocating for &'a str {
}
}

/// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/ascii.rs
Expand Up @@ -20,7 +20,7 @@ use iter::Iterator;
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;
Expand Down
4 changes: 0 additions & 4 deletions src/libstd/os.rs
Expand Up @@ -56,8 +56,6 @@ use vec::Vec;
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 {
Expand Down Expand Up @@ -708,8 +706,6 @@ pub fn self_exe_name() -> Option<Path> {

#[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| {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/prelude.rs
Expand Up @@ -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};
Expand Down

0 comments on commit ba707fb

Please sign in to comment.