pub struct SizeLimit(/* private fields */);Expand description
A byte limit that is either absent or a positive number of bytes up to
MAX_FILE_SIZE_LIMIT.
The TOML spelling of “unlimited” is 0; it exists only at that edge, so no
consumer re-checks for it. Deserializes from an integer and rejects an
out-of-range value at load time.
§Examples
use mcpls_core::config::SizeLimit;
let limit = SizeLimit::new(100).unwrap();
assert!(limit.admits(100));
assert!(!limit.admits(101));
assert!(SizeLimit::UNLIMITED.admits(u64::MAX));
assert_eq!(SizeLimit::new(0).unwrap(), SizeLimit::UNLIMITED);
assert!(SizeLimit::new(u64::MAX).is_err());Implementations§
Source§impl SizeLimit
impl SizeLimit
Sourcepub const fn new(bytes: u64) -> Result<Self, InvalidSizeLimit>
pub const fn new(bytes: u64) -> Result<Self, InvalidSizeLimit>
A limit of bytes, where 0 means unlimited.
§Errors
Returns InvalidSizeLimit above MAX_FILE_SIZE_LIMIT.
Sourcepub const fn from_static(bytes: u64) -> Self
pub const fn from_static(bytes: u64) -> Self
A limit from a literal, checked at compile time when evaluated in a
const context.
§Panics
Panics if bytes is above MAX_FILE_SIZE_LIMIT.
Sourcepub const fn get(self) -> Option<NonZeroU64>
pub const fn get(self) -> Option<NonZeroU64>
The limit in bytes, or None when unlimited.
Trait Implementations§
impl Copy for SizeLimit
Source§impl<'de> Deserialize<'de> for SizeLimit
impl<'de> Deserialize<'de> for SizeLimit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for SizeLimit
impl StructuralPartialEq for SizeLimit
Auto Trait Implementations§
impl Freeze for SizeLimit
impl RefUnwindSafe for SizeLimit
impl Send for SizeLimit
impl Sync for SizeLimit
impl Unpin for SizeLimit
impl UnsafeUnpin for SizeLimit
impl UnwindSafe for SizeLimit
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.