about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <aochagavia92@gmail.com>2014-07-04 22:18:11 +0200
committerAdolfo OchagavĂ­a <aochagavia92@gmail.com>2014-07-15 19:55:19 +0200
commit173baac495485848335cf5ffd52fcd4d061d6d50 (patch)
treec317887201701d515bb8c12d79fb094abe9899ae /src
parent05baf9b10c762dd65407ad13e8b1c72e614fd75e (diff)
downloadrust-173baac495485848335cf5ffd52fcd4d061d6d50.tar.gz
rust-173baac495485848335cf5ffd52fcd4d061d6d50.zip
Deprecate str::from_byte
Replaced by `String::from_byte`

[breaking-change]
Diffstat (limited to 'src')
-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")
 }