|
@@ -362,44 +362,44 @@ impl_to_primitive_float!(f64);
|
|
|
|
|
|
/// A generic trait for converting a number to a value.
|
|
|
pub trait FromPrimitive: Sized {
|
|
|
- /// Convert an `isize` to return an optional value of this type. If the
|
|
|
- /// value cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `isize` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_isize(n: isize) -> Option<Self> {
|
|
|
n.to_i64().and_then(FromPrimitive::from_i64)
|
|
|
}
|
|
|
|
|
|
- /// Convert an `i8` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `i8` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_i8(n: i8) -> Option<Self> {
|
|
|
FromPrimitive::from_i64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert an `i16` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `i16` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_i16(n: i16) -> Option<Self> {
|
|
|
FromPrimitive::from_i64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert an `i32` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `i32` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_i32(n: i32) -> Option<Self> {
|
|
|
FromPrimitive::from_i64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert an `i64` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `i64` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
fn from_i64(n: i64) -> Option<Self>;
|
|
|
|
|
|
- /// Convert an `i128` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `i128` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
///
|
|
|
/// This method is only available with feature `i128` enabled on Rust >= 1.26.
|
|
|
///
|
|
|
- /// The default implementation converts through `from_i64()`. Types implementing
|
|
|
+ /// The default implementation converts through `from_i64()`. Types implementing
|
|
|
/// this trait should override this method if they can represent a greater range.
|
|
|
#[inline]
|
|
|
#[cfg(has_i128)]
|
|
@@ -407,44 +407,44 @@ pub trait FromPrimitive: Sized {
|
|
|
n.to_i64().and_then(FromPrimitive::from_i64)
|
|
|
}
|
|
|
|
|
|
- /// Convert a `usize` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts a `usize` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_usize(n: usize) -> Option<Self> {
|
|
|
n.to_u64().and_then(FromPrimitive::from_u64)
|
|
|
}
|
|
|
|
|
|
- /// Convert an `u8` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `u8` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_u8(n: u8) -> Option<Self> {
|
|
|
FromPrimitive::from_u64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert an `u16` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `u16` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_u16(n: u16) -> Option<Self> {
|
|
|
FromPrimitive::from_u64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert an `u32` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `u32` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_u32(n: u32) -> Option<Self> {
|
|
|
FromPrimitive::from_u64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert an `u64` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `u64` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
fn from_u64(n: u64) -> Option<Self>;
|
|
|
|
|
|
- /// Convert an `u128` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts an `u128` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
///
|
|
|
/// This method is only available with feature `i128` enabled on Rust >= 1.26.
|
|
|
///
|
|
|
- /// The default implementation converts through `from_u64()`. Types implementing
|
|
|
+ /// The default implementation converts through `from_u64()`. Types implementing
|
|
|
/// this trait should override this method if they can represent a greater range.
|
|
|
#[inline]
|
|
|
#[cfg(has_i128)]
|
|
@@ -452,15 +452,15 @@ pub trait FromPrimitive: Sized {
|
|
|
n.to_u64().and_then(FromPrimitive::from_u64)
|
|
|
}
|
|
|
|
|
|
- /// Convert a `f32` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts a `f32` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_f32(n: f32) -> Option<Self> {
|
|
|
FromPrimitive::from_f64(From::from(n))
|
|
|
}
|
|
|
|
|
|
- /// Convert a `f64` to return an optional value of this type. If the
|
|
|
- /// type cannot be represented by this value, then `None` is returned.
|
|
|
+ /// Converts a `f64` to return an optional value of this type. If the
|
|
|
+ /// value cannot be represented by this type, then `None` is returned.
|
|
|
#[inline]
|
|
|
fn from_f64(n: f64) -> Option<Self> {
|
|
|
match n.to_i64() {
|