Skip to main content

JsonDecodeAttempt

Struct JsonDecodeAttempt 

Source
pub struct JsonDecodeAttempt<'a, R, Q>{ /* private fields */ }
Available on crate feature json only.
Expand description

I/O accounting and transactional value admission for one JSON decode.

Dropping an attempt rolls back JSON value accounting. Raw and normalized input charges remain committed, including while unwinding from a panic.

§Type Parameters

  • R - Caller-defined resource identity retained by limits and errors.
  • Q - Exact unsigned quantity used for measurements and accounting.

§Examples

use qubit_budget::json::JsonDecodeLimits;
use qubit_budget::json::JsonDecodeSession;
use qubit_budget::json::JsonMeasurement;

let limits = JsonDecodeLimits::builder().max_nodes(1_usize).build();
let mut session = JsonDecodeSession::from_limits(limits);
let mut attempt = session.begin_value();
attempt.try_admit(JsonMeasurement::Null { depth: 1 }).expect("null should fit");
attempt.commit()?;

Implementations§

Source§

impl<'a, R, Q> JsonDecodeAttempt<'a, R, Q>
where R: Clone, Q: ResourceQuantity,

Source

pub fn try_consume_input_bytes( &mut self, amount: usize, ) -> Result<(), MeasuredBudgetError<R, Q>>

Charges raw input bytes immediately when that budget is configured.

Returns a quantity-conversion or budget error without changing the configured input budget on failure. An absent input budget is ignored.

§Parameters
  • amount - Number of raw input bytes to charge immediately.
§Returns

Ok(()) when the operation completes successfully.

§Errors

Returns MeasuredBudgetError when a native measurement cannot fit Q or a configured limit rejects it.

Source

pub fn try_consume_normalized_input_bytes( &mut self, amount: usize, ) -> Result<(), MeasuredBudgetError<R, Q>>

Charges normalized input bytes immediately when that budget is set.

Returns a quantity-conversion or budget error without changing the configured normalized budget on failure. An absent budget is ignored.

§Parameters
  • amount - Number of normalized input bytes to charge immediately.
§Returns

Ok(()) when the operation completes successfully.

§Errors

Returns MeasuredBudgetError when a native measurement cannot fit Q or a configured limit rejects it.

Source

pub fn try_admit( &mut self, measurement: JsonMeasurement, ) -> Result<(), MeasuredBudgetError<R, Q>>

Stages one JSON measurement for publication by Self::commit.

Returns the transaction’s conversion or value-limit error. A failure leaves this attempt’s working value state and all I/O charges unchanged, and poisons later value admissions and commit. I/O failures alone do not poison the value transaction.

§Parameters
  • measurement - Native JSON measurement to convert or admit.
§Returns

Ok(()) when the operation completes successfully.

§Errors

Returns MeasuredBudgetError when a native measurement cannot fit Q or a configured limit rejects it.

Source

pub fn input_budget(&self) -> Option<&ResourceBudget<R, Q>>

Returns the raw input budget while the attempt exclusively owns it.

§Returns

Returns the raw input budget while the attempt exclusively owns it.

None indicates that the corresponding limit or budget dimension is unconfigured.

Source

pub fn normalized_input_budget(&self) -> Option<&ResourceBudget<R, Q>>

Returns the normalized input budget while the attempt owns it.

§Returns

Returns the normalized input budget while the attempt owns it.

None indicates that the corresponding limit or budget dimension is unconfigured.

Source

pub fn used_nodes(&self) -> Option<Q>

Returns staged node usage when the node limit is configured.

§Returns

Returns staged node usage when the node limit is configured.

None indicates that the corresponding limit or budget dimension is unconfigured.

Source

pub const fn remaining_nodes(&self) -> Option<Q>

Returns staged remaining node capacity when the node limit is set.

§Returns

Returns staged remaining node capacity when the node limit is set.

None indicates that the corresponding limit or budget dimension is unconfigured.

Source

pub fn used_payload_bytes(&self) -> Option<Q>

Returns staged payload usage when the payload limit is configured.

§Returns

Returns staged payload usage when the payload limit is configured.

None indicates that the corresponding limit or budget dimension is unconfigured.

Source

pub const fn remaining_payload_bytes(&self) -> Option<Q>

Returns staged remaining payload capacity when the payload limit is set.

§Returns

Returns staged remaining payload capacity when the payload limit is set.

None indicates that the corresponding limit or budget dimension is unconfigured.

Source

pub fn value_transaction_mut(&mut self) -> &mut JsonValueTransaction<'a, R, Q>

Returns the mutable transaction that holds this attempt’s value state.

§Returns

Returns the mutable transaction that holds this attempt’s value state.

Source

pub fn commit(self) -> Result<(), MeasuredBudgetError<R, Q>>

Publishes this attempt’s staged value state without rolling back I/O.

§Returns

Ok(()) after publishing the staged value state.

§Errors

Returns the first value-admission error when the attempt is poisoned.

Auto Trait Implementations§

§

impl<'a, R, Q> !UnwindSafe for JsonDecodeAttempt<'a, R, Q>

§

impl<'a, R, Q> Freeze for JsonDecodeAttempt<'a, R, Q>
where Option<&'a mut ResourceBudget<R, Q>>: Freeze, JsonValueTransaction<'a, R, Q>: Freeze,

§

impl<'a, R, Q> RefUnwindSafe for JsonDecodeAttempt<'a, R, Q>

§

impl<'a, R, Q> Send for JsonDecodeAttempt<'a, R, Q>
where Option<&'a mut ResourceBudget<R, Q>>: Send, JsonValueTransaction<'a, R, Q>: Send,

§

impl<'a, R, Q> Sync for JsonDecodeAttempt<'a, R, Q>
where Option<&'a mut ResourceBudget<R, Q>>: Sync, JsonValueTransaction<'a, R, Q>: Sync,

§

impl<'a, R, Q> Unpin for JsonDecodeAttempt<'a, R, Q>
where Option<&'a mut ResourceBudget<R, Q>>: Unpin, JsonValueTransaction<'a, R, Q>: Unpin,

§

impl<'a, R, Q> UnsafeUnpin for JsonDecodeAttempt<'a, R, Q>

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.