]> git.lizzy.rs Git - rust.git/commitdiff
libcore: use unboxed closures in `float_to_str_bytes_common`
authorJorge Aparicio <japaricious@gmail.com>
Sat, 6 Dec 2014 17:05:38 +0000 (12:05 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sat, 13 Dec 2014 22:03:46 +0000 (17:03 -0500)
src/libcore/fmt/float.rs

index 400ce76baa0d27a865a2f1051c6bb36070f363d4..fb4d91e912a3b65c75706dd0d394f1d34d064c58 100644 (file)
@@ -20,6 +20,7 @@
 use iter::{range, DoubleEndedIteratorExt};
 use num::{Float, FPNaN, FPInfinite, ToPrimitive};
 use num::cast;
+use ops::FnOnce;
 use result::Result::Ok;
 use slice::{mod, SlicePrelude};
 use str::StrPrelude;
@@ -84,7 +85,7 @@ pub enum SignFormat {
 ///   between digit and exponent sign `'e'`.
 /// - Panics if `radix` > 25 and `exp_format` is `ExpBin` due to conflict
 ///   between digit and exponent sign `'p'`.
-pub fn float_to_str_bytes_common<T: Float, U>(
+pub fn float_to_str_bytes_common<T: Float, U, F>(
     num: T,
     radix: uint,
     negative_zero: bool,
@@ -92,8 +93,10 @@ pub fn float_to_str_bytes_common<T: Float, U>(
     digits: SignificantDigits,
     exp_format: ExponentFormat,
     exp_upper: bool,
-    f: |&[u8]| -> U
-) -> U {
+    f: F
+) -> U where
+    F: FnOnce(&[u8]) -> U,
+{
     assert!(2 <= radix && radix <= 36);
     match exp_format {
         ExpDec if radix >= DIGIT_E_RADIX       // decimal exponent 'e'