pub struct TypeSchema {
pub id: SchemaId,
pub name: String,
pub fields: Vec<FieldDef>,
pub data_size: usize,
pub component_types: Option<Vec<String>>,
pub enum_info: Option<EnumInfo>,
pub content_hash: Option<[u8; 32]>,
/* private fields */
}Expand description
Schema describing the memory layout of a declared type
Fields§
§id: SchemaIdUnique schema identifier
name: StringType name (e.g., “Candle”, “Trade”)
fields: Vec<FieldDef>Field definitions with computed offsets
data_size: usizeTotal size of the object data in bytes (excluding header)
component_types: Option<Vec<String>>Component types (for intersection types, tracks which types were merged) Maps field name to the source type name for decomposition
enum_info: Option<EnumInfo>Enum-specific information (if this is an enum type)
content_hash: Option<[u8; 32]>Content hash (SHA-256) derived from structural definition. Computed lazily and cached. Skipped during serialization since it is derived.
Implementations§
Source§impl TypeSchema
impl TypeSchema
Sourcepub fn from_intersection(
name: impl Into<String>,
schemas: &[&TypeSchema],
) -> Result<Self, SchemaError>
pub fn from_intersection( name: impl Into<String>, schemas: &[&TypeSchema], ) -> Result<Self, SchemaError>
Create an intersection type schema by merging multiple schemas. Returns an error if any field names collide.
Sourcepub fn is_intersection(&self) -> bool
pub fn is_intersection(&self) -> bool
Check if this schema is an intersection type
Sourcepub fn get_component_types(&self) -> Option<&[String]>
pub fn get_component_types(&self) -> Option<&[String]>
Get the component types if this is an intersection
Sourcepub fn field_source(&self, field_name: &str) -> Option<&str>
pub fn field_source(&self, field_name: &str) -> Option<&str>
Get the source type for a field (for decomposition)
Sourcepub fn fields_for_component(&self, component_name: &str) -> Vec<&FieldDef>
pub fn fields_for_component(&self, component_name: &str) -> Vec<&FieldDef>
Get fields belonging to a specific component type (for decomposition)
Source§impl TypeSchema
impl TypeSchema
Sourcepub fn field_kind(&self, idx: usize) -> Option<NativeKind>
pub fn field_kind(&self, idx: usize) -> Option<NativeKind>
Project field at idx to its strict-typed marshal/wire/snapshot
NativeKind. Returns None if idx is out of range or if the
field’s type is FieldType::Any (which has no strict-typed
projection — see super::field_types::FieldKindError).
Used by Phase 2b wire/snapshot kind-threading to read each
TypedObject slot with the correct kind without probing the
slot’s bits.
Sourcepub fn new(
name: impl Into<String>,
field_defs: Vec<(String, FieldType)>,
) -> Self
pub fn new( name: impl Into<String>, field_defs: Vec<(String, FieldType)>, ) -> Self
Create a new type schema with the given fields, allocating an ID
from the current ambient super::TypeSchemaRegistry.
Since B1.4 the ID is drawn from super::current_registry rather
than the process-global NEXT_SCHEMA_ID static. Callers that need
a caller-supplied ID should use TypeSchema::with_id.
Sourcepub fn with_id(
id: SchemaId,
name: impl Into<String>,
field_defs: Vec<(String, FieldType)>,
) -> Self
pub fn with_id( id: SchemaId, name: impl Into<String>, field_defs: Vec<(String, FieldType)>, ) -> Self
Create a new type schema with a caller-supplied schema ID.
Used by super::TypeSchemaRegistry::register_type_scoped (and tests)
to construct schemas whose IDs come from a per-registry counter rather
than the legacy global static.
Sourcepub fn field_offset(&self, name: &str) -> Option<usize>
pub fn field_offset(&self, name: &str) -> Option<usize>
Get field offset by name (returns None if field doesn’t exist)
Sourcepub fn field_index(&self, name: &str) -> Option<u16>
pub fn field_index(&self, name: &str) -> Option<u16>
Get field index by name
Sourcepub fn field_by_index(&self, index: u16) -> Option<&FieldDef>
pub fn field_by_index(&self, index: u16) -> Option<&FieldDef>
Get field by index
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Number of fields in this schema
Sourcepub fn field_names(&self) -> impl Iterator<Item = &str>
pub fn field_names(&self) -> impl Iterator<Item = &str>
Iterator over field names
Sourcepub fn get_enum_info(&self) -> Option<&EnumInfo>
pub fn get_enum_info(&self) -> Option<&EnumInfo>
Get enum info if this is an enum type
Sourcepub fn variant_id(&self, variant_name: &str) -> Option<u16>
pub fn variant_id(&self, variant_name: &str) -> Option<u16>
Get variant ID by name (for enum types)
Sourcepub fn new_enum(name: impl Into<String>, variants: Vec<EnumVariantInfo>) -> Self
pub fn new_enum(name: impl Into<String>, variants: Vec<EnumVariantInfo>) -> Self
Create an enum schema with variant information, allocating an ID
from the current ambient super::TypeSchemaRegistry.
Layout:
- Field 0: __variant (I64) - variant discriminator at offset 0
- Field 1+: __payload_N (Any) - payload fields at offset 8, 16, etc.
Since B1.4 the ID is drawn from super::current_registry rather
than the process-global NEXT_SCHEMA_ID static.
Sourcepub fn new_enum_with_id(
id: SchemaId,
name: impl Into<String>,
variants: Vec<EnumVariantInfo>,
) -> Self
pub fn new_enum_with_id( id: SchemaId, name: impl Into<String>, variants: Vec<EnumVariantInfo>, ) -> Self
Create an enum schema with a caller-supplied ID.
Sourcepub fn compute_content_hash(&self) -> [u8; 32]
pub fn compute_content_hash(&self) -> [u8; 32]
Compute the content hash (SHA-256) from the structural definition.
The hash is derived deterministically from:
- The type name
- Fields sorted by name, each contributing field name + field type string
- Enum variant info (if present), sorted by variant name
For recursive type references (Object("Foo")), only the type name is
hashed to avoid infinite recursion.
Sourcepub fn content_hash(&mut self) -> [u8; 32]
pub fn content_hash(&mut self) -> [u8; 32]
Return the cached content hash, computing and caching it if needed.
Sourcepub fn bind_to_arrow_schema(
&self,
arrow_schema: &ArrowSchema,
) -> Result<TypeBinding, TypeBindingError>
pub fn bind_to_arrow_schema( &self, arrow_schema: &ArrowSchema, ) -> Result<TypeBinding, TypeBindingError>
Bind this TypeSchema to an Arrow schema, producing a TypeBinding.
Validates that every field in the TypeSchema has a compatible column in the Arrow schema. Returns a mapping from TypeSchema field index → Arrow column index.
Sourcepub fn from_canonical(canonical: &CanonicalType) -> Self
pub fn from_canonical(canonical: &CanonicalType) -> Self
Create a type schema from a canonical type (for evolved types)
This converts the semantic CanonicalType representation into a JIT-ready TypeSchema with proper field offsets and types.
Trait Implementations§
Source§impl Clone for TypeSchema
impl Clone for TypeSchema
Source§fn clone(&self) -> TypeSchema
fn clone(&self) -> TypeSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more