#[non_exhaustive]
pub struct ParseConfig { pub allow_trailing_commas: bool, pub recursion_limit: Option<usize>, pub allow_all_types_at_root: bool, }
Expand description

A JSON Value parsing configuration.

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.
§allow_trailing_commas: bool

If true, allows trailing commas when parsing arrays and objects. If false, trailing commas will cause an ErrorKind::IllegalTrailingComma to be returned.

§recursion_limit: Option<usize>

If present, nested arrays and objects will be limited to recursion_limit levels of nesting. If not present, no checks will be performed which can cause a stack overflow with very deeply nested payloads.

§allow_all_types_at_root: bool

If true, only arrays or objects will be allowed to parse at the root of the JSON payload.

Implementations§

source§

impl ParseConfig

source

pub const fn new() -> Self

Returns the default configuration:

let config = justjson::parser::ParseConfig::new();
assert_eq!(config.allow_trailing_commas, false);
assert_eq!(config.recursion_limit, Some(128));
assert_eq!(config.allow_all_types_at_root, true);
source

pub const fn strict() -> Self

Returns a strict configuration, which differs from the default configuration by only allowing objects and arrays at the root:

let config = justjson::parser::ParseConfig::strict();
assert_eq!(config.allow_trailing_commas, false);
assert_eq!(config.recursion_limit, Some(128));
assert_eq!(config.allow_all_types_at_root, false);
source

pub const fn without_recursion_limit(self) -> Self

Disables recursuion limit testing.

Note: Malicious payloads may be able to cause stack overflows to occur if this is disabled.

source

pub const fn with_recursion_limit(self, limit: usize) -> Self

Sets the maximum recursion limit to limit.

source

pub const fn allowing_all_types_at_root(self, allow_all: bool) -> Self

Sets whether to allow all types at the root of the JSON payload. If false, only arrays and objects will be allowed at the root of the JSON payload.

source

pub const fn allowing_trailing_commas(self) -> Self

Allows trailing commas when parsing objects and arrays.

use justjson::parser::ParseConfig;
use justjson::Value;

let source = r#"{"a":[true,],}"#;
Value::from_json(source).expect_err("not enabled by default");
let config = ParseConfig::new().allowing_trailing_commas();
Value::from_json_with_config(source, config).expect("now parses");

Trait Implementations§

source§

impl Clone for ParseConfig

source§

fn clone(&self) -> ParseConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ParseConfig

source§

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

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

impl Default for ParseConfig

source§

fn default() -> Self

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

impl PartialEq for ParseConfig

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ParseConfig

source§

impl Eq for ParseConfig

source§

impl StructuralEq for ParseConfig

source§

impl StructuralPartialEq for ParseConfig

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> 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,

§

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>,

§

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>,

§

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.