pub struct ContractEnvelope { /* private fields */ }Expand description
A strict semantic Contract plus namespaced, non-semantic ecosystem metadata.
§Extensions are outside the canonical identities
The extension map is side-band data by design: contract_id and
interface_id are computed over the Contract alone, so adding, removing,
or editing an extension never moves a semantic identity
(tests/artifact_identity.rs pins this, and docs/architecture.md’s
identity table records it). Only the artifact identity over the envelope
bytes (ArtifactKind::ContractEnvelopeJsonV1) covers extensions,
because they are in those bytes.
Extension names are validated fail-closed: a reverse-domain namespace
(dot-separated segments of lowercase letters, digits, and hyphens)
followed by /v<integer> with no leading zero, e.g.
org.candid-core.field-names/v1. Values are arbitrary JSON, bounded in
aggregate by Limits::max_value_bytes.
§The org.candid-core.field-names/v1 extension (issue #152)
The one extension this repository itself emits, via
candid-core compile <path> --envelope: the field-name table as an array
of [container, id, name] triples — named labels only, sorted,
deduplicated — exactly the table TsNames::from_source_info builds from
the provenance sidecar and the TypeScript runtime’s schemaFromContract
consumes (hash-enforced, so a lying table fails closed there). The
semantic Contract stores only authoritative label ids; this extension
lets one self-describing document carry the names too, without touching
the canonical format or its identities.
Implementations§
Source§impl ContractEnvelope
impl ContractEnvelope
pub fn new(contract: Contract) -> Self
pub fn contract(&self) -> &Contract
pub fn extensions(&self) -> &BTreeMap<String, Value>
pub fn insert_extension( &mut self, name: impl Into<String>, value: Value, limits: &Limits, ) -> Result<(), ContractValidationError>
pub fn insert_extension_with_context( &mut self, name: impl Into<String>, value: Value, context: &RuntimeContext, ) -> Result<(), ContractValidationError>
pub fn validate(&self, limits: &Limits) -> Result<(), ContractValidationError>
pub fn validate_with_context( &self, context: &RuntimeContext, ) -> Result<(), ContractValidationError>
Sourcepub fn from_json_with_limits(
input: &str,
limits: &Limits,
) -> Result<Self, ContractJsonError>
pub fn from_json_with_limits( input: &str, limits: &Limits, ) -> Result<Self, ContractJsonError>
Parse, validate, and canonicalize an envelope JSON document under caller-supplied limits.
Sourcepub fn from_json_with_context(
input: &str,
context: &RuntimeContext,
) -> Result<Self, ContractJsonError>
pub fn from_json_with_context( input: &str, context: &RuntimeContext, ) -> Result<Self, ContractJsonError>
Bounded parse: max_input_bytes is enforced before decoding, and the
nested Contract and the extension map are validated on one budget.
Sourcepub fn from_slice_with_limits(
input: &[u8],
limits: &Limits,
) -> Result<Self, ContractJsonError>
pub fn from_slice_with_limits( input: &[u8], limits: &Limits, ) -> Result<Self, ContractJsonError>
Bounded parse from bytes.
pub fn from_slice_with_context( input: &[u8], context: &RuntimeContext, ) -> Result<Self, ContractJsonError>
Sourcepub fn to_json_pretty_with_limits(
&self,
limits: &Limits,
) -> Result<String, ContractValidationError>
pub fn to_json_pretty_with_limits( &self, limits: &Limits, ) -> Result<String, ContractValidationError>
Serialize the envelope under caller-supplied limits.
Sourcepub fn to_json_pretty_with_context(
&self,
context: &RuntimeContext,
) -> Result<String, ContractValidationError>
pub fn to_json_pretty_with_context( &self, context: &RuntimeContext, ) -> Result<String, ContractValidationError>
Like Contract::to_json_pretty_with_context, this revalidates and
charges the rendered length against max_canonicalization_work.
Trait Implementations§
Source§impl Clone for ContractEnvelope
impl Clone for ContractEnvelope
Source§fn clone(&self) -> ContractEnvelope
fn clone(&self) -> ContractEnvelope
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContractEnvelope
impl Debug for ContractEnvelope
impl Eq for ContractEnvelope
Source§impl PartialEq for ContractEnvelope
impl PartialEq for ContractEnvelope
Source§impl Serialize for ContractEnvelope
impl Serialize for ContractEnvelope
impl StructuralPartialEq for ContractEnvelope
Auto Trait Implementations§
impl Freeze for ContractEnvelope
impl RefUnwindSafe for ContractEnvelope
impl Send for ContractEnvelope
impl Sync for ContractEnvelope
impl Unpin for ContractEnvelope
impl UnsafeUnpin for ContractEnvelope
impl UnwindSafe for ContractEnvelope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.