Skip to main content

ValueWireEncodePreflight

Struct ValueWireEncodePreflight 

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

Performs conservative resource checks before Wire V1 sorting and formatting.

The checker accumulates conservative lower bounds across successful calls. Each public check is atomic: if it returns an error, all counters are restored to their values before that call. The checker does not serialize, retain a sorting index, or replace the authoritative final JsonEncodeSession checks.

§Examples

use qubit_budget::MeasuredBudgetError;
use qubit_budget::json::JsonEncodeLimits;
use qubit_budget::json::JsonResource;
use qubit_value::Value;
use qubit_value::ValueWireEncodePreflight;

let limits = JsonEncodeLimits::builder().max_nodes(2_usize).build();
let mut preflight = ValueWireEncodePreflight::new(limits);
preflight.check_value(&Value::from(1_i32))?;
preflight.check_value(&Value::from(2_i32))?;

Implementations§

Source§

impl ValueWireEncodePreflight

Source

pub fn new(limits: JsonEncodeLimits) -> Self

Creates a checker with zero accumulated usage from one limit profile.

Source

pub fn new_value_limits(limits: JsonValueLimits) -> Self

Creates a checker with zero accumulated usage for value-only limits.

The outer output budget remains unconfigured because another protocol envelope is expected to account for it.

Source

pub fn new_u64_limits(limits: JsonEncodeLimitsU64<JsonResource, u64>) -> Self

Creates a checker from the u64 profile used by configuration wire limits.

Values greater than usize::MAX on the current platform saturate at usize::MAX instead of wrapping or truncating.

Source

pub fn check_value( &mut self, value: &Value, ) -> Result<(), MeasuredBudgetError<JsonResource, usize>>

Checks and accumulates one scalar value at the root of a payload.

Returns the first exceeded JSON resource limit. If checking fails, the accumulated state is restored to its value before this call.

Source

pub fn check_values( &mut self, values: &MultiValues, ) -> Result<(), MeasuredBudgetError<JsonResource, usize>>

Checks and accumulates one homogeneous collection at the payload root.

Returns the first exceeded JSON resource limit. If checking fails, the accumulated state is restored to its value before this call.

Source

pub fn check_container( &mut self, value: &ValueContainer, ) -> Result<(), MeasuredBudgetError<JsonResource, usize>>

Checks and accumulates an explicit scalar-or-collection payload.

Returns the first exceeded JSON resource limit. If checking fails, the accumulated state is restored to its value before this call.

Trait Implementations§

Source§

impl Clone for ValueWireEncodePreflight

Source§

fn clone(&self) -> ValueWireEncodePreflight

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 ValueWireEncodePreflight

Source§

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

Formats the value using the given formatter. Read more

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> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value. Read more
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 = !

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.