Skip to main content

Contract

Struct Contract 

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

The wire-semantics Contract consumed by host runtimes.

declarations supplies named roots for the arena. Comments, source spelling, and raw source are kept in the SourceInfo sidecar (compiler feature), not here.

Implementations§

Source§

impl Contract

Source

pub fn format(&self) -> &str

Source

pub fn format_version(&self) -> u32

Source

pub fn semantics_profile(&self) -> &str

Source

pub fn canonicalization_profile(&self) -> &str

Source

pub fn identities(&self) -> &ContractIdentities

Source

pub fn contract_id(&self) -> &str

Source

pub fn interface_id(&self) -> Option<&str>

Source

pub fn producer(&self) -> &ProducerInfo

Source

pub fn types(&self) -> &[TypeNode]

Source

pub fn declarations(&self) -> &[Declaration]

Source

pub fn actor(&self) -> Option<&Actor>

Source

pub fn validate(&self) -> Result<(), ContractValidationError>

Validate graph structure and verify its content identities.

Source

pub fn validate_with_limits( &self, limits: &Limits, ) -> Result<(), ContractValidationError>

Source

pub fn validate_with_context( &self, context: &RuntimeContext, ) -> Result<(), ContractValidationError>

Source

pub fn canonicalize(&self) -> Result<Self, ContractValidationError>

Return a deterministically re-indexed copy with freshly calculated identities. This is useful at JSON trust boundaries.

Source

pub fn canonicalize_with_limits( &self, limits: &Limits, ) -> Result<Self, ContractValidationError>

Source

pub fn canonicalize_with_context( &self, context: &RuntimeContext, ) -> Result<Self, ContractValidationError>

Source

pub fn to_json_pretty(&self) -> Result<String, ContractValidationError>

Serialize validated canonical JSON under Limits::default.

A Contract built with raised limits can fail here. Use Self::to_json_pretty_with_limits or Self::to_json_pretty_with_context to serialize under the caller’s own policy.

Source

pub fn to_json_pretty_with_limits( &self, limits: &Limits, ) -> Result<String, ContractValidationError>

Serialize validated canonical JSON under caller-supplied limits.

This revalidates and recanonicalizes, so it consumes the structural limits construction consumed and charges the rendered length against max_canonicalization_work. Raising only the limit that gated construction is therefore not always sufficient; see Self::to_json_pretty_with_context.

Source

pub fn to_json_pretty_with_context( &self, context: &RuntimeContext, ) -> Result<String, ContractValidationError>

Serialize validated canonical JSON under the caller’s context.

Consumes two distinct budgets: the structural limits that gated construction, and max_canonicalization_work, against which the rendered byte length is charged. A caller who raised only a structural limit (for example max_string_bytes) to build the Contract may still need to raise max_canonicalization_work to render it.

For a completely unbounded render, serde Serialize is implemented on Contract directly; it consults no limits and performs no revalidation. That path is for trusted, already-validated values.

Source

pub fn from_json(input: &str) -> Result<Self, ContractJsonError>

Parse, validate, and canonicalize a Contract JSON document under Limits::default.

Source

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

Source

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

Bounded parse: max_input_bytes is enforced before the document is decoded, and decode and validation share one budget.

Source

pub fn from_slice_with_limits( input: &[u8], limits: &Limits, ) -> Result<Self, ContractJsonError>

Parse, validate, and canonicalize Contract JSON bytes under caller-supplied limits.

Source

pub fn from_slice_with_context( input: &[u8], context: &RuntimeContext, ) -> Result<Self, ContractJsonError>

Bounded parse from bytes. Equivalent to Self::from_json_with_context without requiring the caller to validate UTF-8 first.

Source

pub fn try_from_raw(raw: RawContract) -> Result<Self, ContractValidationError>

Source

pub fn try_from_raw_with_limits( raw: RawContract, limits: &Limits, ) -> Result<Self, ContractValidationError>

Source

pub fn try_from_raw_with_context( raw: RawContract, context: &RuntimeContext, ) -> Result<Self, ContractValidationError>

Source§

impl Contract

Trait Implementations§

Source§

impl Clone for Contract

Source§

fn clone(&self) -> Contract

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 Contract

Source§

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

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

impl Eq for Contract

Source§

impl From<&Contract> for RawContract

Source§

fn from(contract: &Contract) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Contract

Source§

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

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 Contract

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.