pub struct TypeSchemaRegistry { /* private fields */ }Expand description
Registry of type schemas.
Each registry owns its own schema-ID counter via next_id. This is the
per-Runtime replacement for the legacy process-global NEXT_SCHEMA_ID
static: two registries built with TypeSchemaRegistry::new_with_stdlib
assign IDs from their own domains and do not observe each other’s state.
The counter is not currently consulted by the historic TypeSchema::new
path (which still bumps the global static), but can be allocated via
TypeSchemaRegistry::allocate_id and used with
TypeSchema::with_id. During the B1 migration window both paths coexist.
Implementations§
Source§impl TypeSchemaRegistry
impl TypeSchemaRegistry
Sourcepub fn allocate_id(&self) -> SchemaId
pub fn allocate_id(&self) -> SchemaId
Allocate a fresh schema ID from this registry’s per-instance counter.
IDs allocated via this method are independent of the legacy
process-global NEXT_SCHEMA_ID static. Used together with
TypeSchema::with_id to construct schemas whose IDs are isolated per
registry (and therefore per Runtime).
Sourcepub fn ensure_next_id_above(&self, max_existing_id: SchemaId)
pub fn ensure_next_id_above(&self, max_existing_id: SchemaId)
Ensure all future allocations from this registry yield IDs strictly
greater than max_existing_id.
Used after loading externally compiled bytecode whose schemas already
have assigned IDs — mirrors the legacy
ensure_next_schema_id_above helper at a per-registry scope.
Sourcepub fn register(&mut self, schema: TypeSchema)
pub fn register(&mut self, schema: TypeSchema)
Register a type schema
Sourcepub fn register_type(
&mut self,
name: impl Into<String>,
fields: Vec<(String, FieldType)>,
) -> SchemaId
pub fn register_type( &mut self, name: impl Into<String>, fields: Vec<(String, FieldType)>, ) -> SchemaId
Register a type with field definitions
Sourcepub fn register_type_with_annotations(
&mut self,
name: impl Into<String>,
fields: Vec<(String, FieldType)>,
field_annotations: Vec<Vec<FieldAnnotation>>,
) -> SchemaId
pub fn register_type_with_annotations( &mut self, name: impl Into<String>, fields: Vec<(String, FieldType)>, field_annotations: Vec<Vec<FieldAnnotation>>, ) -> SchemaId
Register a type with field definitions and per-field annotations.
Each entry in field_annotations corresponds to the field at the same
index in fields. Annotations such as @alias("wire_name") are stored
on the resulting FieldDef so that serialization and deserialization
boundaries can use wire_name() instead of the field name.
Sourcepub fn get(&self, name: &str) -> Option<&TypeSchema>
pub fn get(&self, name: &str) -> Option<&TypeSchema>
Get schema by name
Sourcepub fn get_by_id(&self, id: SchemaId) -> Option<&TypeSchema>
pub fn get_by_id(&self, id: SchemaId) -> Option<&TypeSchema>
Get schema by ID
Sourcepub fn max_schema_id(&self) -> Option<SchemaId>
pub fn max_schema_id(&self) -> Option<SchemaId>
Highest schema ID currently stored in this registry.
Sourcepub fn field_offset(&self, type_name: &str, field_name: &str) -> Option<usize>
pub fn field_offset(&self, type_name: &str, field_name: &str) -> Option<usize>
Get field offset for a type/field combination
Sourcepub fn type_count(&self) -> usize
pub fn type_count(&self) -> usize
Number of registered types
Sourcepub fn type_names(&self) -> impl Iterator<Item = &str>
pub fn type_names(&self) -> impl Iterator<Item = &str>
Iterator over all registered type names
Sourcepub fn with_stdlib_types() -> Self
pub fn with_stdlib_types() -> Self
Create a registry with common stdlib types pre-registered.
Since B1.7 all registrations draw their IDs from the registry’’’s per-instance counter — no process-global or ambient counter is consulted. This keeps two independently constructed registries isolated.
Sourcepub fn with_stdlib_types_and_builtin_ids() -> (Self, BuiltinSchemaIds)
pub fn with_stdlib_types_and_builtin_ids() -> (Self, BuiltinSchemaIds)
Create a registry with stdlib types and return both registry and builtin IDs.
Since B1.7 all registrations draw their IDs from the registry’’’s per-instance counter — no process-global or ambient counter is consulted.
Sourcepub fn register_type_scoped(
&mut self,
name: impl Into<String>,
fields: Vec<(String, FieldType)>,
) -> SchemaId
pub fn register_type_scoped( &mut self, name: impl Into<String>, fields: Vec<(String, FieldType)>, ) -> SchemaId
Register a type whose ID is drawn from this registry’s per-instance
counter rather than the process-global NEXT_SCHEMA_ID.
Preferred replacement for register_type inside
new_with_stdlib and any future per-Runtime registration pathways.
Sourcepub fn register_enum_scoped(
&mut self,
name: impl Into<String>,
variants: Vec<EnumVariantInfo>,
) -> SchemaId
pub fn register_enum_scoped( &mut self, name: impl Into<String>, variants: Vec<EnumVariantInfo>, ) -> SchemaId
Register an enum whose ID is drawn from this registry’s per-instance
counter. See register_type_scoped.
Sourcepub fn new_with_stdlib() -> Self
pub fn new_with_stdlib() -> Self
Create a registry seeded with the canonical stdlib schemas (Row / Option / Result / builtin fixed-layout), using the registry’s own per-instance ID counter rather than the legacy global static.
This is the entry point for per-Runtime schema isolation. Two
registries constructed with new_with_stdlib assign IDs from
independent domains and do not observe each other’s state.
Note: some schema constructors (e.g. when builtin_schemas uses
TypeSchema::new) still fall through to the global counter during the
B1 migration window; only the registry-level register_type_scoped
path is fully isolated. See the parity tests in this module for the
invariants that hold today.
Sourcepub fn compute_all_hashes(&mut self)
pub fn compute_all_hashes(&mut self)
Compute content hashes for all registered schemas.
Sourcepub fn get_by_content_hash(&self, hash: &[u8; 32]) -> Option<&TypeSchema>
pub fn get_by_content_hash(&self, hash: &[u8; 32]) -> Option<&TypeSchema>
Look up a schema by its content hash.
Returns the first schema whose cached or computed content hash matches.
For best performance, call compute_all_hashes first.
Sourcepub fn merge(&mut self, other: TypeSchemaRegistry)
pub fn merge(&mut self, other: TypeSchemaRegistry)
Merge another registry into this one
Schemas from other are added to this registry. If a schema with the
same name already exists, it is NOT overwritten (first registration
wins). If the incoming schema’’’s numeric ID already maps to a
different name in self.by_id, it is skipped — this preserves the
first by_id binding so callers that resolve names through the
ID domain of the pre-existing registry still find what they
registered. (Pre-B1.7 this never happened because all registries
drew IDs from a single process-global counter; B1.7 retired that
counter in favour of per-instance ones, so fresh registries can
produce overlapping ID ranges when merged.)
Sourcepub fn register_predeclared_any_schema(&self, fields: &[String]) -> SchemaId
pub fn register_predeclared_any_schema(&self, fields: &[String]) -> SchemaId
Register (or retrieve) a predeclared schema with FieldType::Any
columns for the given ordered field set.
Intended for compile-time schema derivation paths (extensions, comptime, printing helpers) that need runtime object construction without a user-declared type. Repeated calls with identical field names return the same cached ID.
Sourcepub fn lookup_predeclared_by_id(&self, id: SchemaId) -> Option<TypeSchema>
pub fn lookup_predeclared_by_id(&self, id: SchemaId) -> Option<TypeSchema>
Look up a predeclared schema by ID.
Sourcepub fn mirror_predeclared_any_schema(&self, fields: &[String], id: SchemaId)
pub fn mirror_predeclared_any_schema(&self, fields: &[String], id: SchemaId)
Mirror a predeclared schema with a caller-supplied ID.
Used during the B1 migration window by
super::register_predeclared_any_schema so a single SchemaId
owned by the process-wide fallback registry is also visible
through the per-Runtime ambient registry. Idempotent: a second
call with the same ID is a no-op.
Sourcepub fn lookup_predeclared_id_by_field_order(
&self,
fields: &[&str],
) -> Option<SchemaId>
pub fn lookup_predeclared_id_by_field_order( &self, fields: &[&str], ) -> Option<SchemaId>
Look up a predeclared schema ID by an ordered field signature (fast path).
Sourcepub fn lookup_predeclared_by_field_set(
&self,
fields: &[&str],
) -> Option<TypeSchema>
pub fn lookup_predeclared_by_field_set( &self, fields: &[&str], ) -> Option<TypeSchema>
Order-insensitive predeclared schema lookup by field set.