Skip to content

Commit 173baac

Browse files
committed
Deprecate str::from_byte
Replaced by `String::from_byte` [breaking-change]
1 parent 05baf9b commit 173baac

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/libcollections/string.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl String {
9191
Err(vec)
9292
}
9393
}
94-
94+
9595
/// Convert a vector of chars to a string
9696
///
9797
/// # Example
@@ -137,6 +137,23 @@ impl String {
137137
buf
138138
}
139139

140+
/// Convert a byte to a UTF-8 string
141+
///
142+
/// # Failure
143+
///
144+
/// Fails if invalid UTF-8
145+
///
146+
/// # Example
147+
///
148+
/// ```rust
149+
/// let string = String::from_byte(104);
150+
/// assert_eq!(string.as_slice(), "h");
151+
/// ```
152+
pub fn from_byte(b: u8) -> String {
153+
assert!(b < 128u8);
154+
String::from_char(1, b as char)
155+
}
156+
140157
/// Pushes the given string onto this string buffer.
141158
#[inline]
142159
pub fn push_str(&mut self, string: &str) {

src/test/run-fail/glob-use-std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use std::*;
1717

1818
fn main() {
19-
str::from_byte('a' as u8); // avoid an unused import message
19+
String::from_byte(b'a'); // avoid an unused import message
2020

2121
fail!("fail works")
2222
}

0 commit comments

Comments
 (0)