diff --git a/src/constraint.rs b/src/constraint.rs
index d159420..311457e 100644
--- a/src/constraint.rs
+++ b/src/constraint.rs
@@ -17,13 +17,15 @@ pub trait SubsetOf
{}
impl
SubsetOf for P where Q: SupersetOf {}
+pub trait Sealed {}
+
/// Describes constraints on the set of floating-point values that a proxy type
/// may represent.
///
/// This trait expresses a constraint by filter-mapping values. Note that
/// constraints require `Member`, meaning that the set of real numbers
/// must always be supported and is implied.
-pub trait Constraint: Member
+pub trait Constraint: Member + Sealed
where
T: Float + Primitive,
{
@@ -52,6 +54,8 @@ where
}
}
+impl Sealed for UnitConstraint where T: Float + Primitive {}
+
impl Member for UnitConstraint where T: Float + Primitive {}
impl Member for UnitConstraint where T: Float + Primitive {}
@@ -78,13 +82,14 @@ where
fn filter_map(value: T) -> Option {
if value.is_nan() {
None
- }
- else {
+ } else {
Some(value)
}
}
}
+impl Sealed for NotNanConstraint where T: Float + Primitive {}
+
impl Member for NotNanConstraint where T: Float + Primitive {}
impl Member for NotNanConstraint where T: Float + Primitive {}
@@ -107,11 +112,12 @@ where
fn filter_map(value: T) -> Option {
if value.is_nan() || value.is_infinite() {
None
- }
- else {
+ } else {
Some(value)
}
}
}
+impl Sealed for FiniteConstraint where T: Float + Primitive {}
+
impl Member for FiniteConstraint where T: Float + Primitive {}
diff --git a/src/lib.rs b/src/lib.rs
index 7475068..094b826 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -98,6 +98,7 @@ mod proxy;
use crate::cmp::IntrinsicOrd;
use crate::constraint::{FiniteConstraint, NotNanConstraint, UnitConstraint};
+pub use crate::constraint::Constraint;
pub use crate::proxy::Proxy;
/// Floating-point representation with total ordering.
@@ -167,13 +168,11 @@ where
if self.is_nan() {
CANONICAL_NAN_BITS
- }
- else {
+ } else {
let (mantissa, exponent, sign) = self.integer_decode();
if mantissa == 0 {
CANONICAL_ZERO_BITS
- }
- else {
+ } else {
let exponent = u64::from(unsafe { mem::transmute::(exponent) });
let sign = if sign > 0 { 1u64 } else { 0u64 };
(mantissa & MANTISSA_MASK)
@@ -252,8 +251,7 @@ impl Encoding for f32 {
let exponent: i16 = ((bits >> 23) & 0xff) as i16;
let mantissa = if exponent == 0 {
(bits & 0x7f_ffff) << 1
- }
- else {
+ } else {
(bits & 0x7f_ffff) | 0x80_0000
};
(mantissa as u64, exponent - (127 + 23), sign)
@@ -288,8 +286,7 @@ impl Encoding for f64 {
let exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {
(bits & 0xf_ffff_ffff_ffff) << 1
- }
- else {
+ } else {
(bits & 0xf_ffff_ffff_ffff) | 0x10_0000_0000_0000
};
(mantissa, exponent - (1023 + 52), sign)