Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str: Add method .into_owned(self) -> ~str to Str #8204

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,25 +1079,37 @@ pub mod traits {}
pub trait Str {
/// Work with `self` as a slice.
fn as_slice<'a>(&'a self) -> &'a str;

/// Convert `self` into a ~str.
fn into_owned(self) -> ~str;
}

impl<'self> Str for &'self str {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str { *self }

#[inline]
fn into_owned(self) -> ~str { self.to_owned() }
}

impl<'self> Str for ~str {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
let s: &'a str = *self; s
}

#[inline]
fn into_owned(self) -> ~str { self }
}

impl<'self> Str for @str {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
let s: &'a str = *self; s
}

#[inline]
fn into_owned(self) -> ~str { self.to_owned() }
}

impl<'self> Container for &'self str {
Expand Down