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