pub struct ValueType(/* private fields */);Expand description
Owns immutable recursive identity, canonical layout, and trusted operations.
Capabilities never change type identity. Cloning a descriptor shares its frozen plan; capability installation returns an independently updated plan.
§Examples
use cel_runtime::value_type::ValueType;
let a = ValueType::array(ValueType::leaf::<i32>());
let b = ValueType::array(ValueType::cloneable_leaf::<i32>());
assert!(a.same_shape(&b));Implementations§
Source§impl ValueType
impl ValueType
Sourcepub fn with_type_name(self, name: impl Into<Cow<'static, str>>) -> Self
pub fn with_type_name(self, name: impl Into<Cow<'static, str>>) -> Self
Sets an opaque leaf’s diagnostic name without changing identity or capabilities.
Structural descriptors retain their recursively defined names.
§Examples
let ty = cel_runtime::ValueType::leaf::<i32>().with_type_name("Integer");
assert_eq!(ty.type_name(), "Integer");Sourcepub fn can_clone_for_argument(&self) -> bool
pub fn can_clone_for_argument(&self) -> bool
Returns whether the complete frozen plan supports borrowed argument cloning.
§Examples
assert!(cel_runtime::ValueType::cloneable_leaf::<i32>().can_clone_for_argument());Sourcepub fn type_id(&self) -> TypeId
pub fn type_id(&self) -> TypeId
Returns a diagnostic carrier identity; structural casts require witnesses.
§Examples
assert_eq!(cel_runtime::ValueType::leaf::<i32>().type_id(), std::any::TypeId::of::<i32>());Sourcepub fn type_name(&self) -> &str
pub fn type_name(&self) -> &str
Returns a human-readable diagnostic representation name.
§Examples
assert_eq!(cel_runtime::ValueType::leaf::<i32>().type_name(), "i32");Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the canonical representation size.
§Examples
assert_eq!(cel_runtime::ValueType::leaf::<i32>().size(), 4);Sourcepub fn align(&self) -> usize
pub fn align(&self) -> usize
Returns the canonical representation alignment.
§Examples
assert_eq!(cel_runtime::ValueType::leaf::<u8>().align(), 1);Sourcepub fn tuple_elements(&self) -> Option<&[AssociatedType]>
pub fn tuple_elements(&self) -> Option<&[AssociatedType]>
Borrows source-ordered canonical tuple fields, including empty source unit.
§Examples
assert!(cel_runtime::ValueType::leaf::<i32>().tuple_elements().is_none());Sourcepub fn array_element(&self) -> Option<&ValueType>
pub fn array_element(&self) -> Option<&ValueType>
Borrows the complete canonical array element descriptor.
§Examples
assert!(cel_runtime::ValueType::array(cel_runtime::ValueType::leaf::<i32>()).array_element().is_some());Sourcepub fn push_argument(
&self,
segment: &mut DynSegment,
index: usize,
) -> Result<()>
pub fn push_argument( &self, segment: &mut DynSegment, index: usize, ) -> Result<()>
Registers a borrowed canonical argument read using this complete clone plan.
§Errors
Rejects unavailable cloning or an unrepresentable destination frame.
- Complexity: O(n) registration for n existing stack slots.
§Examples
let mut body = cel_runtime::DynSegment::new::<()>();
cel_runtime::ValueType::cloneable_leaf::<i32>().push_argument(&mut body, 0).unwrap();Sourcepub fn leaf<T: 'static>() -> Self
pub fn leaf<T: 'static>() -> Self
Describes an opaque host leaf without requiring optional capabilities.
§Examples
use cel_runtime::value_type::ValueType;
assert!(!ValueType::leaf::<i32>().same_shape(&ValueType::leaf::<u32>()));Sourcepub fn cloneable_leaf<T: Clone + 'static>() -> Self
pub fn cloneable_leaf<T: Clone + 'static>() -> Self
Describes an opaque host leaf with cloning but no other capabilities.
§Examples
use cel_runtime::value_type::ValueType;
let _ = ValueType::cloneable_leaf::<String>();Sourcepub fn callable(parameters: Vec<ValueType>, result: ValueType) -> Self
pub fn callable(parameters: Vec<ValueType>, result: ValueType) -> Self
Describes a known signature using the existing shared closure carrier.
Cloning shares the compiled body, independent of parameter/result clone capabilities. Equality is unavailable; formatting describes the carrier. This constructor installs ownership directly from the statically known carrier, not from an opaque leaf witness.
- Complexity: O(1), transferring ownership of the signature.
§Examples
use cel_runtime::{ValueType, FnOf, Nil, Leaf, ValueRepr};
assert!(ValueType::callable(vec![], ValueType::leaf::<i32>())
.same_shape(&FnOf::<Nil, Leaf<i32>>::value_type()));Sourcepub fn array(element: ValueType) -> Self
pub fn array(element: ValueType) -> Self
Describes a homogeneous array using the fixed owning header.
Recursive capabilities are present exactly when the element supports them.
§Examples
use cel_runtime::value_type::{ArrayOf, Leaf, ValueRepr, ValueType};
assert!(ValueType::array(ValueType::leaf::<i32>())
.same_shape(&ArrayOf::<Leaf<i32>>::value_type()));Sourcepub fn tuple(elements: Vec<AssociatedType>) -> Result<Self>
pub fn tuple(elements: Vec<AssociatedType>) -> Result<Self>
Computes canonical tuple layout from source-ordered fields.
Supplied offsets are ignored. Empty input describes canonical source unit.
- Complexity: O(n) time and space for n immediate fields.
§Errors
Returns an error if the recursive padded layout exceeds Layout’s bounds.
§Examples
use cel_runtime::value_type::{Nil, ValueRepr, ValueType};
assert!(ValueType::tuple(vec![]).unwrap().same_shape(&Nil::value_type()));Sourcepub fn kind(&self) -> &ValueKind
pub fn kind(&self) -> &ValueKind
Borrows the complete semantic shape without permitting mutation.
§Examples
use cel_runtime::value_type::{Nil, ValueKind, ValueRepr};
assert!(matches!(Nil::value_type().kind(), ValueKind::Tuple(_)));Sourcepub fn layout(&self) -> Layout
pub fn layout(&self) -> Layout
Returns the validated complete physical layout.
§Examples
use cel_runtime::value_type::ValueType;
assert_eq!(ValueType::leaf::<u64>().layout(), std::alloc::Layout::new::<u64>());Sourcepub fn same_shape(&self, other: &Self) -> bool
pub fn same_shape(&self, other: &Self) -> bool
Compares complete semantic identities and every physical field layout.
Capability differences do not affect identity. Equal size and alignment alone never authorize a cast.
- Complexity: O(n) time and O(d) call space for n nodes and nesting depth d.
§Examples
use cel_runtime::value_type::ValueType;
assert!(!ValueType::array(ValueType::leaf::<i32>())
.same_shape(&ValueType::array(ValueType::leaf::<u32>())));Sourcepub fn validate_opaque_leaf(&self, type_id: TypeId) -> Result<()>
pub fn validate_opaque_leaf(&self, type_id: TypeId) -> Result<()>
Checks concrete identity for a legacy conversion that names only a host leaf.
Structural values require explicit representation witnesses, regardless of a shared carrier ID or equal layout. This checks metadata only and does not change the existing typed segment conversion.
§Errors
Returns an error for structural descriptors or a different leaf identity.
§Examples
use std::any::TypeId;
use cel_runtime::value_type::ValueType;
assert!(ValueType::leaf::<String>()
.validate_opaque_leaf(TypeId::of::<String>()).is_ok());
assert!(ValueType::tuple(vec![]).unwrap()
.validate_opaque_leaf(TypeId::of::<()>()).is_err());Sourcepub fn with_clone<R: ValueRepr>(self) -> Result<Self>
pub fn with_clone<R: ValueRepr>(self) -> Result<Self>
Installs a concrete clone adapter after validating the entire witness.
- Complexity: O(n) time and space for n descriptor nodes.
§Errors
Returns an error on any semantic or physical representation mismatch.
§Examples
use cel_runtime::value_type::{Leaf, ValueType};
assert!(ValueType::leaf::<i32>().with_clone::<Leaf<i32>>().is_ok());Sourcepub fn with_equality<R: ValueRepr>(self) -> Result<Self>
pub fn with_equality<R: ValueRepr>(self) -> Result<Self>
Installs concrete equality independently of cloning and formatting.
- Complexity: O(n) time and space for n descriptor nodes.
§Errors
Returns an error on any semantic or physical representation mismatch.
§Examples
use cel_runtime::value_type::{Leaf, ValueType};
assert!(ValueType::leaf::<i32>().with_equality::<Leaf<i32>>().is_ok());Sourcepub fn with_debug<R: ValueRepr>(self) -> Result<Self>
pub fn with_debug<R: ValueRepr>(self) -> Result<Self>
Installs concrete debug formatting independently of other capabilities.
- Complexity: O(n) time and space for n descriptor nodes.
§Errors
Returns an error on any semantic or physical representation mismatch.
§Examples
use cel_runtime::value_type::{Leaf, ValueType};
assert!(ValueType::leaf::<i32>().with_debug::<Leaf<i32>>().is_ok());Sourcepub fn can_compare(&self) -> bool
pub fn can_compare(&self) -> bool
Returns whether this complete descriptor supplies value equality.
§Examples
assert!(!cel_runtime::ValueType::leaf::<i32>().can_compare());