Skip to main content

ValueType

Struct ValueType 

Source
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

Source

pub fn with_type_name(self, name: impl Into<Cow<'static, str>>) -> ValueType

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");
Source

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());
Source

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>());
Source

pub fn type_name(&self) -> &str

Returns a human-readable diagnostic representation name.

§Examples
assert_eq!(cel_runtime::ValueType::leaf::<i32>().type_name(), "i32");
Source

pub fn size(&self) -> usize

Returns the canonical representation size.

§Examples
assert_eq!(cel_runtime::ValueType::leaf::<i32>().size(), 4);
Source

pub fn align(&self) -> usize

Returns the canonical representation alignment.

§Examples
assert_eq!(cel_runtime::ValueType::leaf::<u8>().align(), 1);
Source

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());
Source

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());
Source

pub fn push_argument( &self, segment: &mut DynSegment, index: usize, ) -> Result<(), Error>

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();
Source

pub fn leaf<T>() -> ValueType
where T: 'static,

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>()));
Source

pub fn cloneable_leaf<T>() -> ValueType
where T: Clone + 'static,

Describes an opaque host leaf with cloning but no other capabilities.

§Examples
use cel_runtime::value_type::ValueType;
let _ = ValueType::cloneable_leaf::<String>();
Source

pub fn callable(parameters: Vec<ValueType>, result: ValueType) -> ValueType

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()));
Source

pub fn array(element: ValueType) -> ValueType

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()));
Source

pub fn tuple(elements: Vec<AssociatedType>) -> Result<ValueType, Error>

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()));
Source

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(_)));
Source

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>());
Source

pub fn same_shape(&self, other: &ValueType) -> 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>())));
Source

pub fn validate_opaque_leaf(&self, type_id: TypeId) -> Result<(), Error>

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());
Source

pub fn with_clone<R>(self) -> Result<ValueType, Error>
where R: ValueRepr, <R as ValueRepr>::Value: Clone,

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());
Source

pub fn with_equality<R>(self) -> Result<ValueType, Error>
where R: ValueRepr, <R as ValueRepr>::Value: PartialEq,

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());
Source

pub fn with_debug<R>(self) -> Result<ValueType, Error>
where R: ValueRepr, <R as ValueRepr>::Value: Debug,

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());
Source

pub fn can_compare(&self) -> bool

Returns whether this complete descriptor supplies value equality.

§Examples
assert!(!cel_runtime::ValueType::leaf::<i32>().can_compare());

Trait Implementations§

Source§

impl Clone for ValueType

Source§

fn clone(&self) -> ValueType

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 ValueType

Source§

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

Formats the value using the given formatter. 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, 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> 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.