]> git.lizzy.rs Git - rust.git/commitdiff
Deprecate `str::from_char`
authorAdolfo Ochagavía <aochagavia92@gmail.com>
Fri, 4 Jul 2014 20:08:16 +0000 (22:08 +0200)
committerAdolfo Ochagavía <aochagavia92@gmail.com>
Tue, 15 Jul 2014 17:55:18 +0000 (19:55 +0200)
Use `String::from_char` or `.to_str` instead

[breaking-change]

src/libcollections/str.rs
src/librustc/metadata/encoder.rs
src/libstd/ascii.rs
src/libterm/terminfo/searcher.rs
src/libtime/lib.rs

index 0b8535d1a34026478e6d270bfe22d1c85d03a1e9..2d01d138271b58d9ecf3245f58d81466521120a0 100644 (file)
@@ -125,6 +125,7 @@ pub fn from_utf8_owned(vv: Vec<u8>) -> Result<String, Vec<u8>> {
 /// let string = str::from_byte(104);
 /// assert_eq!(string.as_slice(), "h");
 /// ```
+#[deprecated = "Replaced by String::from_byte"]
 pub fn from_byte(b: u8) -> String {
     assert!(b < 128u8);
     String::from_char(1, b as char)
@@ -139,8 +140,9 @@ pub fn from_byte(b: u8) -> String {
 /// let string = str::from_char('b');
 /// assert_eq!(string.as_slice(), "b");
 /// ```
+#[deprecated = "use String::from_char or char.to_string()"]
 pub fn from_char(ch: char) -> String {
-    String::from_char(ch)
+    String::from_char(1, ch)
 }
 
 /// Convert a vector of chars to a string
index 3cf250a9517d10402fa9fcbc8d4ea8494d1ee912..85b5270e51bae76d83c4e3a4a52021a3d441e91d 100644 (file)
@@ -619,7 +619,7 @@ fn encode_visibility(ebml_w: &mut Encoder, visibility: Visibility) {
         Public => 'y',
         Inherited => 'i',
     };
-    ebml_w.wr_str(str::from_char(ch).as_slice());
+    ebml_w.wr_str(ch.to_str().as_slice());
     ebml_w.end_tag();
 }
 
index 93f026c76f9d3b52674f437b15cba90e976f887e..23a7d45e9281167f16c44b5eb7ce58647c90433f 100644 (file)
@@ -525,7 +525,6 @@ unsafe fn str_copy_map_bytes(string: &str, map: &'static [u8]) -> String {
 mod tests {
     use prelude::*;
     use super::*;
-    use str::from_char;
     use char::from_u32;
     use vec::Vec;
     use str::StrSlice;
@@ -677,8 +676,8 @@ fn test_to_ascii_upper() {
         while i <= 500 {
             let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
                         else { i };
-            assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_upper(),
-                       from_char(from_u32(upper).unwrap()).to_string())
+            assert_eq!((from_u32(i).unwrap()).to_str().as_slice().to_ascii_upper(),
+                       (from_u32(upper).unwrap()).to_str())
             i += 1;
         }
     }
@@ -693,8 +692,8 @@ fn test_to_ascii_lower() {
         while i <= 500 {
             let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
                         else { i };
-            assert_eq!(from_char(from_u32(i).unwrap()).as_slice().to_ascii_lower(),
-                       from_char(from_u32(lower).unwrap()).to_string())
+            assert_eq!((from_u32(i).unwrap()).to_str().as_slice().to_ascii_lower(),
+                       (from_u32(lower).unwrap()).to_str())
             i += 1;
         }
     }
@@ -709,8 +708,8 @@ fn test_into_ascii_upper() {
         while i <= 500 {
             let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
                         else { i };
-            assert_eq!(from_char(from_u32(i).unwrap()).to_string().into_ascii_upper(),
-                       from_char(from_u32(upper).unwrap()).to_string())
+            assert_eq!((from_u32(i).unwrap()).to_str().into_ascii_upper(),
+                       (from_u32(upper).unwrap()).to_str())
             i += 1;
         }
     }
@@ -726,8 +725,8 @@ fn test_into_ascii_lower() {
         while i <= 500 {
             let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
                         else { i };
-            assert_eq!(from_char(from_u32(i).unwrap()).to_string().into_ascii_lower(),
-                       from_char(from_u32(lower).unwrap()).to_string())
+            assert_eq!((from_u32(i).unwrap()).to_str().into_ascii_lower(),
+                       (from_u32(lower).unwrap()).to_str())
             i += 1;
         }
     }
@@ -747,11 +746,8 @@ fn test_eq_ignore_ascii_case() {
             let c = i;
             let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
                         else { c };
-            assert!(from_char(from_u32(i).unwrap()).as_slice()
-                                                   .eq_ignore_ascii_case(
-                                                       from_char(
-                                                           from_u32(lower)
-                                                            .unwrap()).as_slice()));
+            assert!((from_u32(i).unwrap()).to_str().as_slice().eq_ignore_ascii_case(
+                    (from_u32(lower).unwrap()).to_str().as_slice()));
             i += 1;
         }
     }
index 0002b20d205ca9abaf930211a058d3ca2a8e8dd7..dff67fc32db7b66e81efc6824c08369a6126b552 100644 (file)
@@ -59,7 +59,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> {
     // Look for the terminal in all of the search directories
     for p in dirs_to_search.iter() {
         if p.exists() {
-            let f = str::from_char(first_char);
+            let f = first_char.to_str();
             let newp = p.join_many([f.as_slice(), term]);
             if newp.exists() {
                 return Some(box newp);
index 4e20c073ac5924aac26d012ed0856c13001932c5..0690b561c44da7741b76e217ec41459b0f9138aa 100644 (file)
@@ -486,9 +486,7 @@ fn parse_char(s: &str, pos: uint, c: char) -> Result<uint, String> {
         if c == range.ch {
             Ok(range.next)
         } else {
-            Err(format!("Expected {}, found {}",
-                str::from_char(c),
-                str::from_char(range.ch)))
+            Err(format!("Expected {}, found {}", c, range.ch))
         }
     }
 
@@ -789,7 +787,7 @@ fn parse_type(s: &str, pos: uint, ch: char, tm: &mut Tm)
           }
           '%' => parse_char(s, pos, '%'),
           ch => {
-            Err(format!("unknown formatting type: {}", str::from_char(ch)))
+            Err(format!("unknown formatting type: {}", ch))
           }
         }
     }