about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcollections/string.rs19
-rw-r--r--src/test/run-fail/glob-use-std.rs2
2 files changed, 19 insertions, 2 deletions
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")
 }