pub struct RangeCfg<T: Copy + PartialOrd> { /* private fields */ }Expand description
Configuration for limiting the range of a value.
This is often used to configure length limits for variable-length types or collections.
§Examples
use commonware_codec::RangeCfg;
// Limit lengths to 0..=1024 (type inferred as usize)
let cfg = RangeCfg::new(0..=1024);
assert!(cfg.contains(&500));
assert!(!cfg.contains(&2000));
// Allow any length >= 1
let cfg_min = RangeCfg::from(1..);
assert!(cfg_min.contains(&1));
assert!(!cfg_min.contains(&0));
// Works with other integer types
let cfg_u8: RangeCfg<u8> = RangeCfg::new(0u8..=255u8);
assert!(cfg_u8.contains(&128));
let cfg_u32 = RangeCfg::new(0u32..1024u32);
assert!(cfg_u32.contains(&500));Implementations§
Source§impl<T: Copy + PartialOrd> RangeCfg<T>
impl<T: Copy + PartialOrd> RangeCfg<T>
Sourcepub fn new(r: impl RangeBounds<T>) -> Self
pub fn new(r: impl RangeBounds<T>) -> Self
Creates a new RangeCfg from any type implementing RangeBounds<T>.
§Examples
use commonware_codec::RangeCfg;
let cfg = RangeCfg::new(0..=1024);
assert!(cfg.contains(&500));Trait Implementations§
Source§impl<T: Copy + PartialOrd> From<RangeInclusive<T>> for RangeCfg<T>
impl<T: Copy + PartialOrd> From<RangeInclusive<T>> for RangeCfg<T>
Source§fn from(r: RangeInclusive<T>) -> Self
fn from(r: RangeInclusive<T>) -> Self
Converts to this type from the input type.
Source§impl<T: Copy + PartialOrd> From<RangeToInclusive<T>> for RangeCfg<T>
impl<T: Copy + PartialOrd> From<RangeToInclusive<T>> for RangeCfg<T>
Source§fn from(r: RangeToInclusive<T>) -> Self
fn from(r: RangeToInclusive<T>) -> Self
Converts to this type from the input type.
Source§impl<T: Copy + PartialOrd> RangeBounds<T> for RangeCfg<T>
impl<T: Copy + PartialOrd> RangeBounds<T> for RangeCfg<T>
impl<T: Copy + Copy + PartialOrd> Copy for RangeCfg<T>
impl<T: Eq + Copy + PartialOrd> Eq for RangeCfg<T>
impl<T: Copy + PartialOrd> StructuralPartialEq for RangeCfg<T>
Auto Trait Implementations§
impl<T> Freeze for RangeCfg<T>where
T: Freeze,
impl<T> RefUnwindSafe for RangeCfg<T>where
T: RefUnwindSafe,
impl<T> Send for RangeCfg<T>where
T: Send,
impl<T> Sync for RangeCfg<T>where
T: Sync,
impl<T> Unpin for RangeCfg<T>where
T: Unpin,
impl<T> UnwindSafe for RangeCfg<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more