pub struct StringLimits<R, Q = u64>where
Q: ResourceQuantity,{ /* private fields */ }Expand description
Optional point limit for one UTF-8 string’s byte length.
§Type Parameters
R- Caller-defined resource identity retained by limits and errors.Q- Exact unsigned quantity used for measurements and accounting.
§Examples
use qubit_budget::ResourceLimit;
use qubit_budget::StringLimits;
let limits = StringLimits::builder()
.utf8_bytes_limit(ResourceLimit::new("name bytes", 5_u64))
.build();
limits.check("hello").expect("five UTF-8 bytes should fit");
assert!(limits.check("hello!").is_err());Implementations§
Source§impl<R, Q> StringLimits<R, Q>where
Q: ResourceQuantity,
impl<R, Q> StringLimits<R, Q>where
Q: ResourceQuantity,
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates limits with no configured string bound.
§Returns
Creates limits with no configured string bound.
Sourcepub const fn builder() -> StringLimitsBuilder<R, Q>
pub const fn builder() -> StringLimitsBuilder<R, Q>
Sourcepub const fn into_builder(self) -> StringLimitsBuilder<R, Q>
pub const fn into_builder(self) -> StringLimitsBuilder<R, Q>
Converts these limits into a builder for further configuration.
§Returns
Converts these limits into a builder for further configuration.
Sourcepub const fn utf8_bytes_limit(&self) -> Option<&ResourceLimit<R, Q>>
pub const fn utf8_bytes_limit(&self) -> Option<&ResourceLimit<R, Q>>
Returns the configured UTF-8 byte limit, if any.
§Returns
Returns the configured UTF-8 byte limit, if any.
None indicates that the corresponding limit or budget dimension is
unconfigured.
Sourcepub fn check(&self, value: &str) -> Result<(), MeasuredBudgetError<R, Q>>where
R: Clone,
pub fn check(&self, value: &str) -> Result<(), MeasuredBudgetError<R, Q>>where
R: Clone,
Checks one string without mutating the limits.
The measured quantity is the string’s UTF-8 byte length. A configured limit returns a point budget error when the length is too large.
§Parameters
value- UTF-8 string whose byte length is compared with the limit.
§Returns
Ok(()) when the operation completes successfully.
§Errors
Returns MeasuredBudgetError when a native measurement cannot fit Q
or a configured limit rejects it.
Trait Implementations§
Source§impl<R: Clone, Q> Clone for StringLimits<R, Q>where
Q: ResourceQuantity + Clone,
impl<R: Clone, Q> Clone for StringLimits<R, Q>where
Q: ResourceQuantity + Clone,
Source§fn clone(&self) -> StringLimits<R, Q>
fn clone(&self) -> StringLimits<R, Q>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more