Replace StrAllocating.into_owned() with .into_string()
We already have into_string(), but it was implemented in terms of into_owned(). Flip it around and deprecate into_owned(). Remove a few spurious calls to .into_owned() that existed in libregex and librustdoc.
This commit is contained in:
parent
812785e01a
commit
eb98c9eeaa
4 changed files with 19 additions and 24 deletions
|
@ -573,13 +573,13 @@ impl<'t> Replacer for NoExpand<'t> {
|
||||||
|
|
||||||
impl<'t> Replacer for &'t str {
|
impl<'t> Replacer for &'t str {
|
||||||
fn reg_replace<'a>(&'a mut self, caps: &Captures) -> MaybeOwned<'a> {
|
fn reg_replace<'a>(&'a mut self, caps: &Captures) -> MaybeOwned<'a> {
|
||||||
Owned(caps.expand(*self).into_owned())
|
Owned(caps.expand(*self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Replacer for |&Captures|: 'a -> String {
|
impl<'a> Replacer for |&Captures|: 'a -> String {
|
||||||
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
|
fn reg_replace<'r>(&'r mut self, caps: &Captures) -> MaybeOwned<'r> {
|
||||||
Owned((*self)(caps).into_owned())
|
Owned((*self)(caps))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -356,7 +356,7 @@ impl fmt::Show for clean::Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.into_owned()
|
ret
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
clean::Proc(ref decl) => {
|
clean::Proc(ref decl) => {
|
||||||
|
|
|
@ -79,7 +79,7 @@ use mem;
|
||||||
use option::{None, Option, Some};
|
use option::{None, Option, Some};
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use slice::Vector;
|
use slice::Vector;
|
||||||
use slice::{ImmutableVector, MutableVector, CloneableVector};
|
use slice::{ImmutableVector, MutableVector};
|
||||||
use string::String;
|
use string::String;
|
||||||
use vec::Vec;
|
use vec::Vec;
|
||||||
|
|
||||||
|
@ -503,7 +503,7 @@ pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
|
||||||
res.push_bytes(v.slice(subseqidx, total))
|
res.push_bytes(v.slice(subseqidx, total))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Owned(res.into_owned())
|
Owned(res.into_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -608,7 +608,7 @@ impl<'a> Str for MaybeOwned<'a> {
|
||||||
|
|
||||||
impl<'a> StrAllocating for MaybeOwned<'a> {
|
impl<'a> StrAllocating for MaybeOwned<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_owned(self) -> String {
|
fn into_string(self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Slice(s) => s.to_string(),
|
Slice(s) => s.to_string(),
|
||||||
Owned(s) => s
|
Owned(s) => s
|
||||||
|
@ -723,7 +723,7 @@ Section: Trait implementations
|
||||||
/// Any string that can be represented as a slice
|
/// Any string that can be represented as a slice
|
||||||
pub trait StrAllocating: Str {
|
pub trait StrAllocating: Str {
|
||||||
/// Convert `self` into a `String`, not making a copy if possible.
|
/// Convert `self` into a `String`, not making a copy if possible.
|
||||||
fn into_owned(self) -> String;
|
fn into_string(self) -> String;
|
||||||
|
|
||||||
/// Convert `self` into a `String`.
|
/// Convert `self` into a `String`.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -731,10 +731,10 @@ pub trait StrAllocating: Str {
|
||||||
String::from_str(self.as_slice())
|
String::from_str(self.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert `self` into a `String`, not making a copy if possible.
|
#[allow(missing_doc)]
|
||||||
#[inline]
|
#[deprecated = "replaced by .into_string()"]
|
||||||
fn into_string(self) -> String {
|
fn into_owned(self) -> String {
|
||||||
self.into_owned()
|
self.into_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Escape each char in `s` with `char::escape_default`.
|
/// Escape each char in `s` with `char::escape_default`.
|
||||||
|
@ -889,7 +889,7 @@ pub trait StrAllocating: Str {
|
||||||
|
|
||||||
impl<'a> StrAllocating for &'a str {
|
impl<'a> StrAllocating for &'a str {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_owned(self) -> String {
|
fn into_string(self) -> String {
|
||||||
self.to_string()
|
self.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1045,7 +1045,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_concat() {
|
fn test_concat() {
|
||||||
fn t(v: &[String], s: &str) {
|
fn t(v: &[String], s: &str) {
|
||||||
assert_eq!(v.concat(), s.to_str().into_owned());
|
assert_eq!(v.concat(), s.to_str().into_string());
|
||||||
}
|
}
|
||||||
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
|
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
|
||||||
"no".to_string(), "good".to_string()], "youknowI'mnogood");
|
"no".to_string(), "good".to_string()], "youknowI'mnogood");
|
||||||
|
@ -1057,7 +1057,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_connect() {
|
fn test_connect() {
|
||||||
fn t(v: &[String], sep: &str, s: &str) {
|
fn t(v: &[String], sep: &str, s: &str) {
|
||||||
assert_eq!(v.connect(sep), s.to_str().into_owned());
|
assert_eq!(v.connect(sep), s.to_str().into_string());
|
||||||
}
|
}
|
||||||
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
|
t(["you".to_string(), "know".to_string(), "I'm".to_string(),
|
||||||
"no".to_string(), "good".to_string()],
|
"no".to_string(), "good".to_string()],
|
||||||
|
@ -1070,7 +1070,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_concat_slices() {
|
fn test_concat_slices() {
|
||||||
fn t(v: &[&str], s: &str) {
|
fn t(v: &[&str], s: &str) {
|
||||||
assert_eq!(v.concat(), s.to_str().into_owned());
|
assert_eq!(v.concat(), s.to_str().into_string());
|
||||||
}
|
}
|
||||||
t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
|
t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
|
||||||
let v: &[&str] = [];
|
let v: &[&str] = [];
|
||||||
|
@ -1081,7 +1081,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_connect_slices() {
|
fn test_connect_slices() {
|
||||||
fn t(v: &[&str], sep: &str, s: &str) {
|
fn t(v: &[&str], sep: &str, s: &str) {
|
||||||
assert_eq!(v.connect(sep), s.to_str().into_owned());
|
assert_eq!(v.connect(sep), s.to_str().into_string());
|
||||||
}
|
}
|
||||||
t(["you", "know", "I'm", "no", "good"],
|
t(["you", "know", "I'm", "no", "good"],
|
||||||
" ", "you know I'm no good");
|
" ", "you know I'm no good");
|
||||||
|
@ -2162,9 +2162,9 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_maybe_owned_into_owned() {
|
fn test_maybe_owned_into_string() {
|
||||||
assert_eq!(Slice("abcde").into_owned(), "abcde".to_string());
|
assert_eq!(Slice("abcde").into_string(), "abcde".to_string());
|
||||||
assert_eq!(Owned("abcde".to_string()).into_owned(), "abcde".to_string());
|
assert_eq!(Owned("abcde".to_string()).into_string(), "abcde".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -322,11 +322,6 @@ impl Str for String {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StrAllocating for String {
|
impl StrAllocating for String {
|
||||||
#[inline]
|
|
||||||
fn into_owned(self) -> String {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_string(self) -> String {
|
fn into_string(self) -> String {
|
||||||
self
|
self
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue