From 173baac495485848335cf5ffd52fcd4d061d6d50 Mon Sep 17 00:00:00 2001 From: Adolfo OchagavĂ­a Date: Fri, 4 Jul 2014 22:18:11 +0200 Subject: Deprecate str::from_byte Replaced by `String::from_byte` [breaking-change] --- src/libcollections/string.rs | 19 ++++++++++++++++++- src/test/run-fail/glob-use-std.rs | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 9223413fbdf..555f2ee59fc 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -91,7 +91,7 @@ impl String { Err(vec) } } - + /// Convert a vector of chars to a string /// /// # Example @@ -137,6 +137,23 @@ impl String { buf } + /// Convert a byte to a UTF-8 string + /// + /// # Failure + /// + /// Fails if invalid UTF-8 + /// + /// # Example + /// + /// ```rust + /// let string = String::from_byte(104); + /// assert_eq!(string.as_slice(), "h"); + /// ``` + pub fn from_byte(b: u8) -> String { + assert!(b < 128u8); + String::from_char(1, b as char) + } + /// Pushes the given string onto this string buffer. #[inline] pub fn push_str(&mut self, string: &str) { diff --git a/src/test/run-fail/glob-use-std.rs b/src/test/run-fail/glob-use-std.rs index 458a95b91cf..fffe146f7f4 100644 --- a/src/test/run-fail/glob-use-std.rs +++ b/src/test/run-fail/glob-use-std.rs @@ -16,7 +16,7 @@ use std::*; fn main() { - str::from_byte('a' as u8); // avoid an unused import message + String::from_byte(b'a'); // avoid an unused import message fail!("fail works") } -- cgit 1.4.1-3-g733a5