Deprecate str::from_chars
Use `String::from_chars` instead [breaking-change]
This commit is contained in:
parent
211f1caa29
commit
20a6894830
7 changed files with 23 additions and 11 deletions
|
@ -813,7 +813,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
|||
c
|
||||
}
|
||||
} ).collect();
|
||||
str::from_chars(c.as_slice()).to_string()
|
||||
String::from_chars(c.as_slice())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
|
|
|
@ -148,11 +148,11 @@ pub fn from_char(ch: char) -> String {
|
|||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::str;
|
||||
/// let chars = ['h', 'e', 'l', 'l', 'o'];
|
||||
/// let string = str::from_chars(chars);
|
||||
/// let string = String::from_chars(chars);
|
||||
/// assert_eq!(string.as_slice(), "hello");
|
||||
/// ```
|
||||
#[deprecated = "use String::from_chars instead"]
|
||||
pub fn from_chars(chs: &[char]) -> String {
|
||||
chs.iter().map(|c| *c).collect()
|
||||
}
|
||||
|
|
|
@ -91,6 +91,20 @@ impl String {
|
|||
Err(vec)
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a vector of chars to a string
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let chars = ['h', 'e', 'l', 'l', 'o'];
|
||||
/// let string = String::from_chars(chars);
|
||||
/// assert_eq!(string.as_slice(), "hello");
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn from_chars(chs: &[char]) -> String {
|
||||
chs.iter().map(|c| *c).collect()
|
||||
}
|
||||
|
||||
/// Return the underlying byte buffer, encoded as UTF-8.
|
||||
#[inline]
|
||||
|
|
|
@ -510,7 +510,7 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
self.chari = closer;
|
||||
let greed = try!(self.get_next_greedy());
|
||||
let inner = str::from_chars(
|
||||
let inner = String::from_chars(
|
||||
self.chars.as_slice().slice(start + 1, closer));
|
||||
|
||||
// Parse the min and max values from the regex.
|
||||
|
@ -944,7 +944,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
fn slice(&self, start: uint, end: uint) -> String {
|
||||
str::from_chars(self.chars.as_slice().slice(start, end)).to_string()
|
||||
String::from_chars(self.chars.as_slice().slice(start, end))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -685,7 +685,7 @@ mod test {
|
|||
let hs = uuid1.to_hyphenated_str();
|
||||
let ss = uuid1.to_string();
|
||||
|
||||
let hsn = str::from_chars(hs.as_slice()
|
||||
let hsn = String::from_chars(hs.as_slice()
|
||||
.chars()
|
||||
.filter(|&c| c != '-')
|
||||
.collect::<Vec<char>>()
|
||||
|
|
|
@ -100,9 +100,7 @@ impl fmt::Show for AsciiArt {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
// Convert each line into a string.
|
||||
let lines = self.lines.iter()
|
||||
.map(|line| {
|
||||
str::from_chars(line.as_slice()).to_string()
|
||||
})
|
||||
.map(|line| String::from_chars(line.as_slice()))
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
// Concatenate the lines together using a new-line.
|
||||
|
|
|
@ -13,13 +13,13 @@ use std::str;
|
|||
pub fn main() {
|
||||
// Chars of 1, 2, 3, and 4 bytes
|
||||
let chs: Vec<char> = vec!('e', 'é', '€', '\U00010000');
|
||||
let s: String = str::from_chars(chs.as_slice()).to_string();
|
||||
let s: String = String::from_chars(chs.as_slice()).to_string();
|
||||
let schs: Vec<char> = s.as_slice().chars().collect();
|
||||
|
||||
assert!(s.len() == 10u);
|
||||
assert!(s.as_slice().char_len() == 4u);
|
||||
assert!(schs.len() == 4u);
|
||||
assert!(str::from_chars(schs.as_slice()).to_string() == s);
|
||||
assert!(String::from_chars(schs.as_slice()) == s);
|
||||
assert!(s.as_slice().char_at(0u) == 'e');
|
||||
assert!(s.as_slice().char_at(1u) == 'é');
|
||||
|
||||
|
|
Loading…
Reference in a new issue