Skip to main content

Lim

Struct Lim 

Source
pub struct Lim<T: PartialOrd + Clone + Debug> { /* private fields */ }
Expand description

A strictly typed bounding limit that guarantees a value stays within defined constraints.

Lim encapsulates a value along with its min and max bounds. Bounds can be configured as inclusive or exclusive. Any mutation to the value or the bounds is strictly validated to maintain the mathematical invariants of the range.

Implementations§

Source§

impl<T: Clone + PartialOrd + Debug> Lim<T>

Source

pub fn new( value: T, min: T, max: T, include_min: bool, include_max: bool, ) -> Result<Self, LimError<T>>

Creates a new Lim instance.

§Arguments
  • value - The initial value.
  • min - The lower bound.
  • max - The upper bound.
  • include_min - Whether the lower bound is inclusive (>=) or exclusive (>).
  • include_max - Whether the upper bound is inclusive (<=) or exclusive (<).
§Errors

Returns LimError::InvalidBounds if min > max. Returns LimError::OutOfBounds if value does not satisfy the bounds.

Source

pub fn value(&self) -> &T

Returns a reference to the current value.

Source

pub fn min(&self) -> &T

Returns a reference to the lower bound.

Source

pub fn max(&self) -> &T

Returns a reference to the upper bound.

Source

pub fn include_min(&self) -> bool

Returns true if the lower bound is inclusive.

Source

pub fn include_max(&self) -> bool

Returns true if the upper bound is inclusive.

Source

pub fn contains(&self, value: &T) -> bool

Checks if a given value satisfies the current bounds.

Source

pub fn set_value(&mut self, value: T) -> Result<(), LimError<T>>

Updates the current value.

§Errors

Returns LimError::OutOfBounds if the new value does not satisfy the current bounds.

Source

pub fn set_min( &mut self, min: T, include_min: bool, clamp: bool, ) -> Result<(), LimError<T>>

Updates the lower bound.

§Arguments
  • min - The new lower bound.
  • include_min - Whether the new bound is inclusive or exclusive.
  • clamp - If true and the current value falls outside the new bound, the value will be clamped to the new bound (if mathematically possible). If false, an error is returned if the value is out of bounds.
§Errors
Source

pub fn set_max( &mut self, max: T, include_max: bool, clamp: bool, ) -> Result<(), LimError<T>>

Updates the upper bound.

§Arguments
  • max - The new upper bound.
  • include_max - Whether the new bound is inclusive or exclusive.
  • clamp - If true and the current value falls outside the new bound, the value will be clamped to the new bound (if mathematically possible). If false, an error is returned if the value is out of bounds.
§Errors
Source

pub fn set_bounds( &mut self, min: T, max: T, include_min: bool, include_max: bool, clamp: bool, ) -> Result<(), LimError<T>>

Updates both the lower and upper bounds simultaneously.

§Arguments
  • min - The new lower bound.
  • max - The new upper bound.
  • include_min - Whether the new lower bound is inclusive or exclusive.
  • include_max - Whether the new upper bound is inclusive or exclusive.
  • clamp - If true, the current value will be clamped to fit within the new bounds.
§Errors

Returns specific LimError variants if the bounds are invalid, if clamping is impossible due to exclusive bounds, or if the value is out of bounds and clamp is false.

Trait Implementations§

Source§

impl<T: Clone + PartialOrd + Clone + Debug> Clone for Lim<T>

Source§

fn clone(&self) -> Lim<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Clone + Copy + PartialOrd + Debug> Copy for Lim<T>

Source§

impl<T: Debug + PartialOrd + Clone + Debug> Debug for Lim<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialOrd + Clone + Debug> Deref for Lim<T>

Allows transparent access to the underlying value.

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de, T> Deserialize<'de> for Lim<T>
where T: Deserialize<'de> + PartialOrd + Clone + Debug,

Implements deserialization, strictly validating the bounds and value invariants during the parsing process.

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for Lim<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Lim<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Lim<T>
where T: RefUnwindSafe,

§

impl<T> Send for Lim<T>
where T: Send,

§

impl<T> Sync for Lim<T>
where T: Sync,

§

impl<T> Unpin for Lim<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Lim<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Lim<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.