Skip to main content

JsonDecodeOptions

Struct JsonDecodeOptions 

Source
pub struct JsonDecodeOptions { /* private fields */ }
Expand description

Configuration switches for crate::LenientJsonDecoder.

Its fields control text normalization, input limits, and error diagnostics. Defaults are intentionally conservative and cover the most common non-fully-trusted text inputs without attempting aggressive repair.

§Examples

use qubit_json::{JsonDecodeOptions, LenientJsonDecoder};

let options = JsonDecodeOptions::strict();
let _decoder = LenientJsonDecoder::new(options);
let _moved_options = options;

Implementations§

Source§

impl JsonDecodeOptions

Source

pub const fn lenient() -> Self

Creates the default lenient option set.

§Returns

An option set that enables every supported normalization rule, applies no input-size limit, and redacts input-derived error details.

Source

pub const fn strict() -> Self

Creates an option set that disables all text-rewriting rules.

The decoder still applies empty-input classification, optional raw and normalized input-size limits, the configured privacy policy, and stable error mapping before or around parsing and deserialization.

§Returns

An option set that leaves input text unchanged, applies no raw or normalized size limit, delegates parsing and deserialization to serde_json, and redacts input-derived error details.

Source

pub const fn trim_whitespace(&self) -> bool

Returns whether leading and trailing whitespace is removed.

§Returns

true when surrounding whitespace is removed; otherwise, false.

Source

pub const fn with_trim_whitespace(self, enabled: bool) -> Self

Returns these options with whitespace trimming enabled or disabled.

§Parameters
  • enabled - Whether to remove surrounding whitespace.
§Returns

The updated option set.

Source

pub const fn strip_utf8_bom(&self) -> bool

Returns whether a leading UTF-8 byte order mark is removed.

§Returns

true when a leading UTF-8 byte order mark is removed; otherwise, false.

Source

pub const fn with_strip_utf8_bom(self, enabled: bool) -> Self

Returns these options with UTF-8 byte order mark stripping configured.

§Parameters
  • enabled - Whether to remove a leading UTF-8 byte order mark.
§Returns

The updated option set.

Source

pub const fn markdown_fence_policy(&self) -> &MarkdownFencePolicy

Returns the policy used to remove one outer Markdown code fence.

§Returns

The configured Markdown fence policy.

§Examples
#![deny(unused_must_use)]
use qubit_json::JsonDecodeOptions;

let options = JsonDecodeOptions::strict();
options.markdown_fence_policy();
Source

pub const fn with_markdown_fence_policy( self, markdown_fence_policy: MarkdownFencePolicy, ) -> Self

Returns these options with a Markdown fence policy.

§Parameters
  • markdown_fence_policy - Policy used to recognize and remove one outer Markdown code fence.
§Returns

The updated option set.

Source

pub const fn escape_control_chars_in_strings(&self) -> bool

Returns whether raw control characters in JSON strings are escaped.

§Returns

true when raw ASCII control characters inside JSON strings are escaped; otherwise, false.

Source

pub const fn with_escape_control_chars_in_strings(self, enabled: bool) -> Self

Returns these options with JSON-string control character escaping configured.

§Parameters
  • enabled - Whether to escape raw ASCII control characters inside JSON strings.
§Returns

The updated option set.

Source

pub const fn max_input_bytes(&self) -> Option<usize>

Returns the raw input byte-size limit.

§Returns

Some(limit) when accepted raw input is capped at limit bytes, or None when the decoder enforces no input-size limit.

Source

pub const fn with_max_input_bytes(self, max_input_bytes: Option<usize>) -> Self

Returns these options with a raw input byte-size limit.

§Parameters
  • max_input_bytes - Some(limit) to cap the raw input at limit bytes, or None to remove the limit.
§Returns

The updated option set.

Source

pub const fn max_normalized_bytes(&self) -> Option<usize>

Returns the normalized JSON byte-size limit.

§Returns

Some(limit) when normalized JSON is capped at limit bytes, or None when the decoder enforces no normalized-size limit.

Source

pub const fn with_max_normalized_bytes( self, max_normalized_bytes: Option<usize>, ) -> Self

Returns these options with a normalized JSON byte-size limit.

The decoder calculates the normalized size before allocating repaired text for raw control characters, so this limit also bounds the allocation caused by supported control-character escaping.

§Parameters
  • max_normalized_bytes - Some(limit) to cap normalized JSON at limit bytes, or None to remove the limit.
§Returns

The updated option set.

Source

pub const fn error_privacy_policy(&self) -> ErrorPrivacyPolicy

Returns the privacy policy applied to decoding error diagnostics.

§Returns

The configured error privacy policy.

Source

pub const fn with_error_privacy_policy( self, error_privacy_policy: ErrorPrivacyPolicy, ) -> Self

Returns these options with the requested error privacy policy.

The policy determines whether serde diagnostics derived from input values are retained in returned errors.

§Parameters
  • error_privacy_policy - Policy applied when constructing decoding errors.
§Returns

The updated option set.

Trait Implementations§

Source§

impl Clone for JsonDecodeOptions

Source§

fn clone(&self) -> JsonDecodeOptions

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 Debug for JsonDecodeOptions

Source§

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

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

impl Default for JsonDecodeOptions

Source§

fn default() -> Self

Creates the default lenient option set.

§Returns

The same option set as Self::lenient.

Source§

impl Eq for JsonDecodeOptions

Source§

impl PartialEq for JsonDecodeOptions

Source§

fn eq(&self, other: &JsonDecodeOptions) -> 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 JsonDecodeOptions

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