Skip to main content

NormalizingJsonDecoder

Struct NormalizingJsonDecoder 

Source
pub struct NormalizingJsonDecoder<'budget, R = JsonResource, Q = usize>{ /* private fields */ }
Expand description

Normalizes non-fully-trusted text before decoding complete JSON documents.

Owned convenience methods prepare and decode in one call. Callers needing borrowed results, custom seeds, or repeated materialization first create a NormalizedJsonDocument and then use a document decoding method.

§Examples

use qubit_budget::json::JsonDecodeLimits;
use qubit_json::decode::NormalizingJsonDecodePolicy;
use qubit_json::decode::NormalizingJsonDecoder;
use serde_json::Value;

let mut decoder = NormalizingJsonDecoder::with_limits(
    NormalizingJsonDecodePolicy::builder().build(),
    JsonDecodeLimits::new(),
);
let value = decoder.decode_str::<Value>("```json\n{\"ok\":true}\n```")?;
assert_eq!(value["ok"], true);

Implementations§

Source§

impl<R, Q> NormalizingJsonDecoder<'static, R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub fn with_limits( policy: NormalizingJsonDecodePolicy, limits: JsonDecodeLimits<R, Q>, ) -> Self

Creates a normalizing decoder with a cumulative session built from explicit limits.

§Parameters
  • policy - Normalization and diagnostic behavior applied before decoding.
  • limits - Input and decoded-value limits used by the cumulative session.
§Returns

A decoder whose accounting starts empty and is constrained by limits.

Source§

impl<'budget, R, Q> NormalizingJsonDecoder<'budget, R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub const fn new( policy: NormalizingJsonDecodePolicy, session: JsonDecodeSession<'budget, R, Q>, ) -> Self

Creates a decoder around a reusable caller-provided session.

§Parameters
  • policy - Normalization and diagnostic behavior applied before decoding.
  • session - Cumulative session receiving input and decoded-value charges.
§Returns

A decoder that owns session until it is consumed by Self::into_session.

Source

pub const fn session(&self) -> &JsonDecodeSession<'budget, R, Q>

Returns the cumulative session for read-only inspection.

The returned reference exposes charges accumulated by completed preparation and decoding operations.

§Returns

A shared reference to the cumulative session.

Source

pub const fn session_mut(&mut self) -> &mut JsonDecodeSession<'budget, R, Q>

Returns mutable access to the cumulative session.

Mutating the session changes the limits and accounting state used by subsequent operations.

§Returns

A mutable reference to the cumulative session.

Source

pub fn into_session(self) -> JsonDecodeSession<'budget, R, Q>

Consumes the decoder and returns its cumulative session.

Ownership of all accumulated accounting state is transferred without resetting it or performing another decode.

§Returns

The session previously owned by this decoder.

Source

pub const fn policy(&self) -> &NormalizingJsonDecodePolicy

Returns the immutable normalization and diagnostic policy.

The returned reference remains tied to this decoder and controls how future input is normalized and how input-derived failures are retained.

§Returns

A shared reference to the configured policy.

Source

pub fn prepare_str<'input>( &mut self, input: &'input str, ) -> Result<NormalizedJsonDocument<'input>, JsonDecodeError<R, Q>>

Normalizes one string and immediately charges its input budgets.

The returned document may borrow input. Later document decoding does not charge its input again and commits only decoded-value usage.

§Parameters
  • input - JSON text to normalize and charge.
§Returns

A normalized document that may borrow input.

§Errors

Returns a structured error when input accounting, UTF-8 validation, or normalization fails.

Source

pub fn prepare_utf8<'input>( &mut self, input: &'input [u8], ) -> Result<NormalizedJsonDocument<'input>, JsonDecodeError<R, Q>>

Charges raw bytes, validates UTF-8, and normalizes one byte slice.

Raw input usage remains charged when UTF-8 validation or normalization fails. The returned document may borrow the original byte slice.

§Parameters
  • input - UTF-8 byte slice to validate, normalize, and charge.
§Returns

A normalized document that may borrow input.

§Errors

Returns a structured error when input accounting, UTF-8 validation, or normalization fails.

Source

pub fn decode_precharged_document<'de, T>( &mut self, document: &'de NormalizedJsonDocument<'_>, ) -> Result<T, JsonDecodeError<R, Q>>
where T: Deserialize<'de>,

Decodes one precharged document and permits results borrowing it.

Preparing the document has already committed its raw and normalized input usage. This method commits only the decoded-value usage.

§Type Parameters
  • T - Target type deserialized from the prepared document.
§Parameters
  • document - Precharged normalized document that outlives the returned value.
§Returns

The deserialized value on success.

§Errors

Returns a structured error when decoded-value accounting, parsing, or deserialization fails.

Source

pub fn decode_precharged_document_seed<'de, S>( &mut self, document: &'de NormalizedJsonDocument<'_>, seed: S, ) -> Result<S::Value, JsonDecodeError<R, Q>>
where S: DeserializeSeed<'de>,

Decodes one precharged document through a caller-provided Serde seed.

Preparing the document has already committed its raw and normalized input usage. This method commits only the decoded-value usage.

§Type Parameters
  • S - Seed controlling construction of the decoded value.
§Parameters
  • document - Precharged normalized document.
  • seed - Serde seed used to deserialize the document.
§Returns

The value produced by seed.

§Errors

Returns a structured error when decoded-value accounting, parsing, or seeded deserialization fails.

Source

pub fn decode_precharged_object_document<'de, T>( &mut self, document: &'de NormalizedJsonDocument<'_>, ) -> Result<T, JsonDecodeError<R, Q>>
where T: Deserialize<'de>,

Decodes one precharged document while requiring a top-level object.

Preparing the document has already committed its raw and normalized input usage. This method commits only the decoded-value usage.

§Type Parameters
  • T - Target type deserialized from the object document.
§Parameters
  • document - Precharged document that outlives the returned value.
§Returns

The deserialized object value on success.

§Errors

Returns a structured error for accounting, parsing, top-level-kind, or deserialization failures.

Source

pub fn decode_precharged_array_document<'de, T>( &mut self, document: &'de NormalizedJsonDocument<'_>, ) -> Result<Vec<T>, JsonDecodeError<R, Q>>
where T: Deserialize<'de>,

Decodes one precharged document while requiring a top-level array.

Preparing the document has already committed its raw and normalized input usage. This method commits only the decoded-value usage.

§Type Parameters
  • T - Element type deserialized from the array.
§Parameters
  • document - Precharged document that outlives the returned elements.
§Returns

The decoded array elements on success.

§Errors

Returns a structured error for accounting, parsing, top-level-kind, or deserialization failures.

Source

pub fn validate_precharged_document( &mut self, document: &NormalizedJsonDocument<'_>, ) -> Result<(), JsonDecodeError<R, Q>>

Validates a precharged document and commits its decoded-value usage.

Preparing the document has already committed its raw and normalized input usage. This method commits only the decoded-value usage.

§Parameters
  • document - Precharged document whose JSON syntax is validated.
§Returns

Ok(()) after the normalized document is valid and its decoded-value usage is committed.

§Errors

Returns a structured error when decoded-value accounting or JSON validation fails.

Source

pub fn decode_str<T>(&mut self, input: &str) -> Result<T, JsonDecodeError<R, Q>>

Normalizes and decodes one string into an owned target value.

§Type Parameters
  • T - Owned target type deserialized from the normalized document.
§Parameters
  • input - JSON text to normalize and decode.
§Returns

The owned deserialized value on success.

§Errors

Returns a structured error when normalization, accounting, parsing, or deserialization fails.

Source

pub fn decode_utf8<T>( &mut self, input: &[u8], ) -> Result<T, JsonDecodeError<R, Q>>

Normalizes and decodes one UTF-8 byte slice into an owned target value.

§Type Parameters
  • T - Owned target type deserialized from the normalized document.
§Parameters
  • input - UTF-8 JSON bytes to normalize and decode.
§Returns

The owned deserialized value on success.

§Errors

Returns a structured error when normalization, accounting, UTF-8 validation, parsing, or deserialization fails.

Source

pub fn decode_object_str<T>( &mut self, input: &str, ) -> Result<T, JsonDecodeError<R, Q>>

Normalizes and decodes one string while requiring a top-level object.

§Parameters
  • input - JSON text whose normalized root must be an object.
§Returns

The owned deserialized object value on success.

§Errors

Returns a structured error for normalization, accounting, parsing, top-level-kind, or deserialization failures.

Source

pub fn decode_object_utf8<T>( &mut self, input: &[u8], ) -> Result<T, JsonDecodeError<R, Q>>

Normalizes and decodes one UTF-8 byte slice while requiring a top-level object.

§Parameters
  • input - UTF-8 JSON bytes whose normalized root must be an object.
§Returns

The owned deserialized object value on success.

§Errors

Returns a structured error for normalization, accounting, UTF-8 validation, parsing, top-level-kind, or deserialization failures.

Source

pub fn decode_array_str<T>( &mut self, input: &str, ) -> Result<Vec<T>, JsonDecodeError<R, Q>>

Normalizes and decodes one string while requiring a top-level array.

§Parameters
  • input - JSON text whose normalized root must be an array.
§Returns

The owned decoded array elements on success.

§Errors

Returns a structured error for normalization, accounting, parsing, top-level-kind, or deserialization failures.

Source

pub fn decode_array_utf8<T>( &mut self, input: &[u8], ) -> Result<Vec<T>, JsonDecodeError<R, Q>>

Normalizes and decodes one UTF-8 byte slice while requiring a top-level array.

§Parameters
  • input - UTF-8 JSON bytes whose normalized root must be an array.
§Returns

The owned decoded array elements on success.

§Errors

Returns a structured error for normalization, accounting, UTF-8 validation, parsing, top-level-kind, or deserialization failures.

Source

pub fn decode_value( &mut self, input: &str, ) -> Result<Value, JsonDecodeError<R, Q>>

Normalizes and decodes one string into a dynamic JSON value.

§Parameters
  • input - JSON text to normalize and materialize as a value tree.
§Returns

The materialized JSON value on success.

§Errors

Returns a structured error when normalization, accounting, parsing, or value construction fails.

Trait Implementations§

Source§

impl<'budget, R: Debug, Q> Debug for NormalizingJsonDecoder<'budget, R, Q>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'budget, R = JsonResource, Q = usize> !UnwindSafe for NormalizingJsonDecoder<'budget, R, Q>

§

impl<'budget, R, Q> Freeze for NormalizingJsonDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Freeze,

§

impl<'budget, R, Q> RefUnwindSafe for NormalizingJsonDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: RefUnwindSafe,

§

impl<'budget, R, Q> Send for NormalizingJsonDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Send,

§

impl<'budget, R, Q> Sync for NormalizingJsonDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Sync,

§

impl<'budget, R, Q> Unpin for NormalizingJsonDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: Unpin,

§

impl<'budget, R, Q> UnsafeUnpin for NormalizingJsonDecoder<'budget, R, Q>
where JsonDecodeEngine<'budget, R, Q>: UnsafeUnpin,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.