pub struct SchemaGraph {
pub defs: Vec<SchemaTypeDef>,
pub root: SchemaType,
}Expand description
A self-contained schema graph in the recursive in-memory form.
Anywhere a schema travels with a value (typed pair, oplog custom
payload, REST/RPC envelope, public oplog rendering), the payload owns its
own SchemaGraph — there is no implicit external registry that
consumers must look up.
Recursive references between types go through SchemaType::Ref, pointing
at named definitions in SchemaGraph::defs.
§Single-root vs multi-root carriers
The common case is single-root: one SchemaGraph describes one
payload, with root as the entry type and defs as the named-type
registry reachable from it.
Multi-root carriers (today, agent-layer carriers such as
[crate::schema::agent::AgentTypeSchema] and
[crate::schema::agent::AgentDependencySchema]) use the same shape
purely as a definition registry: many roots embedded elsewhere in the
carrier reference shared types in defs, and the SchemaGraph::root
field is a sentinel (see SchemaGraph::empty). Such carriers must
not be passed to root-oriented walkers/renderers as if root were the
payload root.
Fields§
§defs: Vec<SchemaTypeDef>Named type definitions in this graph. The defining set is exactly the
types reachable from root (directly or transitively) that need to be
named — typically because they participate in a recursive cycle or are
referenced multiple times.
root: SchemaTypeRoot schema type. Anonymous types appear inline; named types appear
as SchemaType::Ref.
Implementations§
Source§impl SchemaGraph
impl SchemaGraph
Sourcepub fn anonymous(root: SchemaType) -> SchemaGraph
pub fn anonymous(root: SchemaType) -> SchemaGraph
Convenience: an anonymous root schema with no named definitions.
Sourcepub fn empty() -> SchemaGraph
pub fn empty() -> SchemaGraph
Convenience: an empty graph with no definitions and a sentinel root.
Used as the initial value for multi-root carriers such as
[crate::schema::agent::AgentTypeSchema] and
[crate::schema::agent::AgentDependencySchema], where the agent’s
constructor and methods each act as their own root and only the
defs registry is consulted. The root field is a placeholder
(empty record) and is not consumed by agent-layer helpers.
Sourcepub fn lookup(&self, id: &TypeId) -> Option<&SchemaTypeDef>
pub fn lookup(&self, id: &TypeId) -> Option<&SchemaTypeDef>
Look up a named definition by its TypeId.
Sourcepub fn contains_stream_type(&self) -> bool
pub fn contains_stream_type(&self) -> bool
Whether any type reachable from the root is a stream, including unselected alternatives.
Sourcepub fn resolve_ref<'a>(
&'a self,
ty: &'a SchemaType,
) -> Result<&'a SchemaType, RefResolutionError>
pub fn resolve_ref<'a>( &'a self, ty: &'a SchemaType, ) -> Result<&'a SchemaType, RefResolutionError>
Walk through any number of SchemaType::Ref indirections and return
the first non-ref body in this graph. Detects recursive cycles
(RefResolutionError::RecursiveRef) and dangling references
(RefResolutionError::DanglingRef).
Trait Implementations§
Source§impl Clone for SchemaGraph
impl Clone for SchemaGraph
Source§fn clone(&self) -> SchemaGraph
fn clone(&self) -> SchemaGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more