Skip to main content

TypeSchemaRegistry

Struct TypeSchemaRegistry 

Source
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

Source

pub fn new() -> Self

Create a new empty registry

Source

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).

Source

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.

Source

pub fn register(&mut self, schema: TypeSchema)

Register a type schema

Source

pub fn register_type( &mut self, name: impl Into<String>, fields: Vec<(String, FieldType)>, ) -> SchemaId

Register a type with field definitions

Source

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.

Source

pub fn get(&self, name: &str) -> Option<&TypeSchema>

Get schema by name

Source

pub fn get_by_id(&self, id: SchemaId) -> Option<&TypeSchema>

Get schema by ID

Source

pub fn max_schema_id(&self) -> Option<SchemaId>

Highest schema ID currently stored in this registry.

Source

pub fn field_offset(&self, type_name: &str, field_name: &str) -> Option<usize>

Get field offset for a type/field combination

Source

pub fn has_type(&self, name: &str) -> bool

Check if a type is registered

Source

pub fn type_count(&self) -> usize

Number of registered types

Source

pub fn type_names(&self) -> impl Iterator<Item = &str>

Iterator over all registered type names

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn compute_all_hashes(&mut self)

Compute content hashes for all registered schemas.

Source

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.

Source

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.)

Source

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.

Source

pub fn lookup_predeclared_by_id(&self, id: SchemaId) -> Option<TypeSchema>

Look up a predeclared schema by ID.

Source

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.

Source

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).

Source

pub fn lookup_predeclared_by_field_set( &self, fields: &[&str], ) -> Option<TypeSchema>

Order-insensitive predeclared schema lookup by field set.

Trait Implementations§

Source§

impl Clone for TypeSchemaRegistry

Source§

fn clone(&self) -> Self

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 TypeSchemaRegistry

Source§

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

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

impl Default for TypeSchemaRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TypeSchemaRegistry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TypeSchemaRegistry

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

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,