pub enum Ref<T> {
Reference(String),
Embedded(Box<T>),
}Expand description
An object property’s value: EXACTLY ONE of a reference to a named resource
(its canonical URI) or an embedded node (the value itself, carried inline —
derived identity, no $id). The typed twin of the wire form’s
{"$ref": uri} vs embedded-node distinction; the choice between the arms
is authorial and hash-relevant, so it is explicit here, never inferred.
The embedded payload is BOXED (0.6.0, runtime#27). A single-valued
property ranging over its own class — a parent/child hierarchy, the most
ordinary shape an ontology declares — makes struct Objective { supports: Option<Ref<Objective>> }, which has infinite size if the payload is
inline (E0072) and so cannot be generated. The wire form never had that
limit; Box is the indirection Rust needs to match it. Construct with
Ref::embed / Ref::embed_named and read with Ref::value /
Ref::uri and the box is invisible; only a direct Ref::Embedded(x)
pattern sees it (Ref::Embedded(b) => &**b).
Variants§
Reference(String)
A reference to a named resource by its canonical URI.
Embedded(Box<T>)
An embedded value, carried inline (boxed — see the type’s docs).
Implementations§
Source§impl<T> Ref<T>
impl<T> Ref<T>
Sourcepub fn to(uri: impl Into<String>) -> Self
pub fn to(uri: impl Into<String>) -> Self
A reference to a named resource by its canonical URI.
Sourcepub fn to_resource(target: &impl KanonakResource) -> Result<Self, CodecError>
pub fn to_resource(target: &impl KanonakResource) -> Result<Self, CodecError>
A reference to a named resource by the instance itself — resolved
through the target’s envelope id. The target must already carry its
identity; an embedded (id-less) value cannot be referenced.
Sourcepub fn embed_named(value: T, name: impl Into<String>) -> Selfwhere
T: KanonakResource,
pub fn embed_named(value: T, name: impl Into<String>) -> Selfwhere
T: KanonakResource,
An embedded value with its authored dict-key name (hash-relevant).
Sourcepub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
True when this is the reference arm.
Sourcepub fn uri(&self) -> Option<&str>
pub fn uri(&self) -> Option<&str>
The referenced resource’s canonical URI — the reference arm (else None).
Sourcepub fn value_mut(&mut self) -> Option<&mut T>
pub fn value_mut(&mut self) -> Option<&mut T>
The embedded value, mutably — the embedded arm (else None).
Sourcepub fn into_value(self) -> Option<T>
pub fn into_value(self) -> Option<T>
Consume the embedded arm, returning its value (else None).