Skip to main content

HostValue

Struct HostValue 

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

A locally canonical tagged HostValue.

This type serializes as the portable tagged JSON ABI, but deliberately does not implement Deserialize. JSON callers must use HostValue::from_json_with_limits, which decodes a private raw DTO and checks locally canonical scalar encodings before exposing this value.

Every value carries its own measured extent, so the container constructors can reject an over-deep or over-large value in constant time per level. That bound is what makes the recursive operations on this type safe: Drop, Clone, PartialEq, Debug, and Serialize all recurse once per level, and all of them abort the process on a value deep enough to exhaust the stack. Bounding construction is the only chokepoint that covers all five, so there is deliberately no way to obtain a HostValue whose depth was never checked against a caller-supplied limit.

Implementations§

Source§

impl HostValue

Source

pub fn from_json_with_limits( input: &str, limits: &Limits, ) -> Result<Self, HostValueJsonError>

Source

pub fn from_json_with_context( input: &str, context: &RuntimeContext, ) -> Result<Self, HostValueJsonError>

Source

pub fn null() -> Self

Source

pub fn boolean(value: bool) -> Self

Source

pub fn nat(value: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn int(value: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn nat8(value: u8) -> Self

Source

pub fn nat16(value: u16) -> Self

Source

pub fn nat32(value: u32) -> Self

Source

pub fn nat64(value: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn int8(value: i8) -> Self

Source

pub fn int16(value: i16) -> Self

Source

pub fn int32(value: i32) -> Self

Source

pub fn int64(value: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn float32(bits: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn float64(bits: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn text(value: impl Into<String>) -> Self

Source

pub fn reserved() -> Self

Source

pub fn principal(value: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn opt( value: Option<Self>, limits: &Limits, ) -> Result<Self, HostValueJsonError>

Wrap a value in an opt, failing closed past limits.max_value_depth or limits.max_value_elements.

Container construction is fallible because every recursive operation on the result — including Drop, Clone, and Debug, none of which can signal failure — walks one stack frame per level. Refusing to build the value is the only point at which a policy can still be applied.

Source

pub fn vector( values: Vec<Self>, limits: &Limits, ) -> Result<Self, HostValueJsonError>

Build a vec, failing closed past limits.max_value_depth or limits.max_value_elements.

Source

pub fn record( fields: Vec<HostFieldValue>, limits: &Limits, ) -> Result<Self, HostValueJsonError>

Build a record, failing closed past limits.max_value_depth or limits.max_value_elements.

This does not check for duplicate field IDs or agreement with any Contract type; that remains validate_host_value’s contract-directed job.

Source

pub fn variant( id: u32, value: Self, limits: &Limits, ) -> Result<Self, HostValueJsonError>

Build a variant, failing closed past limits.max_value_depth or limits.max_value_elements.

Source

pub fn service(principal: impl Into<String>) -> Result<Self, HostValueJsonError>

Source

pub fn func( principal: impl Into<String>, method: impl Into<String>, ) -> Result<Self, HostValueJsonError>

Trait Implementations§

Source§

impl Clone for HostValue

Source§

fn clone(&self) -> HostValue

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 HostValue

Source§

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

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

impl Eq for HostValue

Source§

impl PartialEq for HostValue

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for HostValue

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for HostValue

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
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.