]> git.lizzy.rs Git - rust.git/commitdiff
Reuse standard methods
authorAndrea Canciani <ranma42@gmail.com>
Mon, 4 Jan 2016 16:29:41 +0000 (17:29 +0100)
committerAndrea Canciani <ranma42@gmail.com>
Mon, 4 Jan 2016 16:51:12 +0000 (17:51 +0100)
Do not hand-code `Result::ok` or `cmp` in tables.rs.

src/etc/unicode.py

index 5a9fbdd3240435705b6be14753cec814fbaac113..57bb36ce994c3fdfadb23fefd83aee105bd66bb2 100755 (executable)
@@ -319,10 +319,8 @@ def emit_property_module(f, mod, tbl, emit):
 def emit_conversions_module(f, to_upper, to_lower, to_title):
     f.write("pub mod conversions {")
     f.write("""
-    use core::cmp::Ordering::{Equal, Less, Greater};
     use core::option::Option;
     use core::option::Option::{Some, None};
-    use core::result::Result::{Ok, Err};
 
     pub fn to_lower(c: char) -> [char; 3] {
         match bsearch_case_table(c, to_lowercase_table) {
@@ -339,14 +337,7 @@ def emit_conversions_module(f, to_upper, to_lower, to_title):
     }
 
     fn bsearch_case_table(c: char, table: &'static [(char, [char; 3])]) -> Option<usize> {
-        match table.binary_search_by(|&(key, _)| {
-            if c == key { Equal }
-            else if key < c { Less }
-            else { Greater }
-        }) {
-            Ok(i) => Some(i),
-            Err(_) => None,
-        }
+        table.binary_search_by(|&(key, _)| key.cmp(&c)).ok()
     }
 
 """)