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 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
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
Layout:
- Field 0: __variant (I64) - variant discriminator at offset 0
- Field 1+: __payload_N (Any) - payload fields at offset 8, 16, etc.
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TypeSchema
impl Debug for TypeSchema
Source§impl<'de> Deserialize<'de> for TypeSchema
impl<'de> Deserialize<'de> for TypeSchema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for TypeSchema
impl RefUnwindSafe for TypeSchema
impl Send for TypeSchema
impl Sync for TypeSchema
impl Unpin for TypeSchema
impl UnsafeUnpin for TypeSchema
impl UnwindSafe for TypeSchema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more