]> git.lizzy.rs Git - rust.git/commitdiff
core: Add from_u32 to the Char trait
authorBrian Anderson <banderson@mozilla.com>
Thu, 9 Oct 2014 00:03:04 +0000 (17:03 -0700)
committerBrian Anderson <banderson@mozilla.com>
Fri, 21 Nov 2014 20:49:51 +0000 (12:49 -0800)
This is the only free function not part of the trait.

src/libcore/char.rs

index e4dc9ce5bd46f4afc0428ba15711b65e1a124718..db58f802643b1b1f1ab0501c9ac0ca9354140922 100644 (file)
@@ -270,6 +270,9 @@ pub trait Char {
     /// Panics if given a radix > 36.
     fn from_digit(num: uint, radix: uint) -> Option<Self>;
 
+    /// Converts from `u32` to a `char`
+    fn from_u32(i: u32) -> Option<char>;
+
     /// Returns the hexadecimal Unicode escape of a character.
     ///
     /// The rules are as follows:
@@ -319,6 +322,9 @@ fn to_digit(&self, radix: uint) -> Option<uint> { to_digit(*self, radix) }
 
     fn from_digit(num: uint, radix: uint) -> Option<char> { from_digit(num, radix) }
 
+    #[inline]
+    fn from_u32(i: u32) -> Option<char> { from_u32(i) }
+
     fn escape_unicode(&self, f: |char|) { escape_unicode(*self, f) }
 
     fn escape_default(&self, f: |char|) { escape_default(*self, f) }