#[non_exhaustive]pub struct Limits {
pub max_depth: u32,
pub max_nodes: u32,
pub max_int_digits: u32,
pub max_input_bytes: u64,
}Expand description
The safety limits of spec section 2.4 (nesting depth, node count, integer
digits) and the maximum input size of D-23, taken by the *_with readers
and, for the first three, by crate::document::Doc::from_raw_with.
use omnist::limits::Limits;
use omnist::formats::json::read_json_with;
let limits = Limits::default().with_max_depth(3);
assert!(read_json_with(r#"{"a": {"b": {"c": 1}}}"#, &limits).is_ok());
let err = read_json_with(r#"{"a": {"b": {"c": {"d": 1}}}}"#, &limits).unwrap_err();
assert!(err.to_string().contains("maximum depth (3)"));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_depth: u32The maximum nesting depth, counted from the Document root (the root
is depth 0). A leaf at exactly this depth is accepted, one level
deeper is refused with document.limit.depth.
0 selects DEFAULT_MAX_DEPTH (200); values above
MAX_DEPTH_CEILING (250) are rejected by Limits::validate.
max_nodes: u32The maximum number of nodes (containers) one Document may hold. A
document with exactly this many is accepted, one more is refused with
document.limit.nodes.
0 selects DEFAULT_MAX_NODES (1 000 000); values above
MAX_NODES_CEILING (10 000 000) are rejected by Limits::validate.
max_int_digits: u32The maximum number of decimal digits in an integer literal, sign
excluded. A literal of exactly this many digits is accepted, one more
is refused with document.limit.int-digits.
0 selects DEFAULT_MAX_INT_DIGITS (4 300); values above
MAX_INT_DIGITS_CEILING (43 000) are rejected by
Limits::validate.
max_input_bytes: u64The maximum input size in bytes (D-23), counted on the input as
received: before a leading BOM is stripped and before decoding. An
input of exactly this many bytes is accepted, one more is refused
with document.limit.input-size at $, ahead of every other
diagnostic. Only the readers use it; a Document built from native
values or a crate::document::RawNode has no input bytes.
0 selects DEFAULT_MAX_INPUT_BYTES (64 MiB); values above
MAX_INPUT_BYTES_CEILING (1 GiB) are rejected by
Limits::validate.
Implementations§
Source§impl Limits
impl Limits
Sourcepub fn with_max_depth(self, n: u32) -> Self
pub fn with_max_depth(self, n: u32) -> Self
These limits with Limits::max_depth set to n (the struct is
#[non_exhaustive], so a downstream crate builds it from
Default with these).
Sourcepub fn with_max_nodes(self, n: u32) -> Self
pub fn with_max_nodes(self, n: u32) -> Self
These limits with Limits::max_nodes set to n.
Sourcepub fn with_max_int_digits(self, n: u32) -> Self
pub fn with_max_int_digits(self, n: u32) -> Self
These limits with Limits::max_int_digits set to n.
Sourcepub fn with_max_input_bytes(self, n: u64) -> Self
pub fn with_max_input_bytes(self, n: u64) -> Self
These limits with Limits::max_input_bytes set to n.
Sourcepub fn effective_max_input_bytes(&self) -> u64
pub fn effective_max_input_bytes(&self) -> u64
The maximum input size these limits select: the configured value, or
DEFAULT_MAX_INPUT_BYTES when it is 0.
Sourcepub fn check_input_len(&self, len: u64, hint: &str) -> Result<(), DocumentError>
pub fn check_input_len(&self, len: u64, hint: &str) -> Result<(), DocumentError>
D-23 for a caller that holds the input as bytes (the CLI): validates
the limits, then refuses an input of len bytes that is over the
maximum with document.limit.input-size at $, and accepts one of
exactly the maximum. hint says how to raise it, in the caller’s own
terms. Call it before decoding the bytes.
Sourcepub fn effective_max_depth(&self) -> u32
pub fn effective_max_depth(&self) -> u32
The maximum depth these limits select: the configured value, or
DEFAULT_MAX_DEPTH when it is 0.
Sourcepub fn effective_max_nodes(&self) -> u32
pub fn effective_max_nodes(&self) -> u32
The maximum node count these limits select: the configured value, or
DEFAULT_MAX_NODES when it is 0.
Sourcepub fn effective_max_int_digits(&self) -> u32
pub fn effective_max_int_digits(&self) -> u32
The maximum integer digit count these limits select: the configured
value, or DEFAULT_MAX_INT_DIGITS when it is 0.
Sourcepub fn validate(&self) -> Result<(), DocumentError>
pub fn validate(&self) -> Result<(), DocumentError>
Checks the limits: each must not exceed its ceiling
(MAX_DEPTH_CEILING, MAX_NODES_CEILING,
MAX_INT_DIGITS_CEILING, MAX_INPUT_BYTES_CEILING). Every
*_with entry point calls this
first and returns its error unchanged (a DocumentError with path
$ and no taxonomy code: it is API misuse, not a document defect).
Trait Implementations§
impl Copy for Limits
impl Eq for Limits
impl StructuralPartialEq for Limits
Auto Trait Implementations§
impl Freeze for Limits
impl RefUnwindSafe for Limits
impl Send for Limits
impl Sync for Limits
impl Unpin for Limits
impl UnsafeUnpin for Limits
impl UnwindSafe for Limits
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.