Skip to main content

Limits

Struct Limits 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§max_depth: u32

The 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: u32

The 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: u32

The 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: u64

The 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

Source

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).

Source

pub fn with_max_nodes(self, n: u32) -> Self

These limits with Limits::max_nodes set to n.

Source

pub fn with_max_int_digits(self, n: u32) -> Self

These limits with Limits::max_int_digits set to n.

Source

pub fn with_max_input_bytes(self, n: u64) -> Self

These limits with Limits::max_input_bytes set to n.

Source

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.

Source

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.

Source

pub fn effective_max_depth(&self) -> u32

The maximum depth these limits select: the configured value, or DEFAULT_MAX_DEPTH when it is 0.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Limits

Source§

fn clone(&self) -> Limits

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 Copy for Limits

Source§

impl Debug for Limits

Source§

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

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

impl Default for Limits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Limits

Source§

impl PartialEq for Limits

Source§

fn eq(&self, other: &Limits) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Limits

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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<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.