pub trait Extent<Discriminant: DiscriminantTag = ()> {
type Scalar: PartialOrd + Copy;
// Required methods
fn minimum(&self) -> Option<Self::Scalar>;
fn maximum(&self) -> Option<Self::Scalar>;
fn optimal(&self) -> Option<Self::Scalar>;
fn none() -> Self;
// Provided method
fn contains(&self, value: Self::Scalar) -> bool { ... }
}Expand description
A trait for deriving values across different extents within a bounded space.
This trait is domain-agnostic and provides a unified interface to compute values at the lower bound, upper bound, and an optimal point under given conditions.
§Methods:
minimum: Returns the lowest permissible or derived value.maximum: Returns the highest permissible or derived value.optimal: Returns the most suitable or preferred value within bounds.
§Usage Scenarios:
- Constraint systems: Determining valid lower and upper limits.
- Optimization problems: Selecting a balanced or ideal value.
- Rate limiting: Bounding operations within safe thresholds.
- Resource allocation: Computing safe vs optimal utilization.
- Financial systems: Sizing deposits, mints, or adjustments.
§Design Notes:
- Fully abstract and reusable across domains.
- Each method is independent and may be computed lazily.
- Implementations may choose to derive values from shared logic.
§Default Discriminant
Discriminant = (): defines a single default extent, meaning one unique set of bounds/derivations is assumed.
Required Associated Types§
Sourcetype Scalar: PartialOrd + Copy
type Scalar: PartialOrd + Copy
The scalar representing the bounded value.
Required Methods§
Sourcefn none() -> Self
fn none() -> Self
Returns an unbounded extent.
This represents the absence of any constraints, where:
Self::minimumreturnsNoneSelf::maximumreturnsNoneSelf::optimalreturnsNone
Useful as a neutral/default extent when no bounds are required.
Provided Methods§
Sourcefn contains(&self, value: Self::Scalar) -> bool
fn contains(&self, value: Self::Scalar) -> bool
Checks whether the given value lies within the extent’s bounds.
Returns true if:
- The value is greater than or equal to
Self::minimum(if available), and - The value is less than or equal to
Self::maximum(if available).
Missing bounds (None) are treated as unbounded in that direction.
This method performs a simple range check and does not enforce optimality or other domain-specific constraints.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.