Trait Extent

Source
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§

Source

type Scalar: PartialOrd + Copy

The scalar representing the bounded value.

Required Methods§

Source

fn minimum(&self) -> Option<Self::Scalar>

Returns the minimum value under given conditions.

Source

fn maximum(&self) -> Option<Self::Scalar>

Returns the maximum value under given conditions.

Source

fn optimal(&self) -> Option<Self::Scalar>

Returns the optimal value under given conditions.

Source

fn none() -> Self

Returns an unbounded extent.

This represents the absence of any constraints, where:

Useful as a neutral/default extent when no bounds are required.

Provided Methods§

Source

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.

Implementors§