Reformat macros.
This commit is contained in:
parent
c32cb5c65b
commit
aab7098acd
20
src/cast.rs
20
src/cast.rs
|
@ -239,31 +239,25 @@ macro_rules! impl_to_primitive_float_to_float {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_to_primitive_float_to_signed_int {
|
macro_rules! impl_to_primitive_float_to_signed_int {
|
||||||
($SrcT:ident, $DstT:ident, $slf:expr) => (
|
($SrcT:ident, $DstT:ident, $slf:expr) => ({
|
||||||
let t = $slf.trunc();
|
let t = $slf.trunc();
|
||||||
if t >= $DstT::MIN as $SrcT && t <= $DstT::MAX as $SrcT {
|
if t >= $DstT::min_value() as $SrcT && t <= $DstT::max_value() as $SrcT {
|
||||||
Some($slf as $DstT)
|
Some($slf as $DstT)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_to_primitive_float_to_unsigned_int {
|
macro_rules! impl_to_primitive_float_to_unsigned_int {
|
||||||
($SrcT:ident, $DstT:ident, $slf:expr) => (
|
($SrcT:ident, $DstT:ident, $slf:expr) => ({
|
||||||
if size_of::<$SrcT>() <= size_of::<$DstT>() {
|
let t = $slf.trunc();
|
||||||
Some($slf as $DstT)
|
if t >= $DstT::min_value() as $SrcT && t <= $DstT::max_value() as $SrcT {
|
||||||
} else {
|
|
||||||
// Make sure the value is in range for the cast.
|
|
||||||
let n = $slf as $DstT;
|
|
||||||
let max_value: $DstT = ::std::$DstT::MAX;
|
|
||||||
if n <= max_value as $DstT {
|
|
||||||
Some($slf as $DstT)
|
Some($slf as $DstT)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_to_primitive_float {
|
macro_rules! impl_to_primitive_float {
|
||||||
|
|
Loading…
Reference in New Issue