Skip to main content

OwnedValue

Struct OwnedValue 

Source
pub struct OwnedValue { /* private fields */ }
Expand description

Owns exactly one live erased value and its complete immutable descriptor.

No clone, equality, formatting, or thread-safety bounds are imposed on the stored value. Consuming errors destroy the original value exactly once; borrowed capability errors leave the original value unchanged.

  • Complexity: Destruction visits every contained value in reverse logical field/element order, using O(d) call space for nesting depth d.

§Examples

use cel_runtime::{owned_value::OwnedValue, value_type::Leaf};
let owner = OwnedValue::new::<Leaf<String>>(String::from("hello"));
assert_eq!(owner.try_into_typed::<Leaf<String>>().unwrap(), "hello");

Implementations§

Source§

impl OwnedValue

Source

pub fn prepare_debug(&self) -> Result<ValueFormatter>

Prepares an independent reusable formatter without consuming or formatting this value.

§Errors

Rejects absent debug capability at any recursive node.

§Examples
use cel_runtime::{Leaf, OwnedValue, ValueType};
let value = OwnedValue::new::<Leaf<i32>>(7)
    .with_value_type(ValueType::leaf::<i32>().with_debug::<Leaf<i32>>().unwrap()).unwrap();
assert_eq!(value.prepare_debug().unwrap().format(&value).unwrap(), "7");
Source

pub fn into_fields(self) -> Result<Vec<Self>>

Splits a canonical tuple into independent source-ordered field owners.

Nested arrays retain their payload allocations; no leaf is cloned.

§Errors

Rejects a nontuple owner without transferring any field ownership.

  • Complexity: O(n + s) field allocations and raw moves for n fields and s bytes.
§Examples
use cel_runtime::{OwnedValue, Cons, Leaf, Nil, IntoCStackList};
let tuple = OwnedValue::new::<Cons<Leaf<i32>, Nil>>((7,).into_c_stack_list());
let fields = tuple.into_fields().unwrap();
assert_eq!(fields.len(), 1);
Source

pub fn new<R: ValueRepr>(value: R::Value) -> Self

Takes ownership using the sealed witness’s canonical descriptor.

Moving an array copies only its header and preserves its element allocation.

  • Complexity: O(n) descriptor construction plus one concrete value move, for n witness nodes; no contained values are cloned.
§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::Leaf};
let _ = OwnedValue::new::<Leaf<String>>(String::from("owned"));
Source

pub fn value_type(&self) -> &ValueType

Borrows this whole value’s frozen descriptor.

§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::{Leaf, ValueType}};
let owner = OwnedValue::new::<Leaf<i32>>(1);
assert!(owner.value_type().same_shape(&ValueType::leaf::<i32>()));
Source

pub fn with_value_type(self, value_type: ValueType) -> Result<Self>

Attaches independently configured capabilities after complete shape validation.

The live representation and allocation do not change.

  • Complexity: O(n) comparison time and O(d) call space for n type nodes and nesting depth d.
§Errors

Returns an error if any identity or physical layout differs. On error the consumed original is destroyed exactly once using its original descriptor; none of the supplied descriptor’s value hooks execute.

§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::{Leaf, ValueType}};
let owner = OwnedValue::new::<Leaf<String>>(String::from("clone me"))
    .with_value_type(ValueType::cloneable_leaf::<String>()).unwrap();
assert!(owner.try_clone().is_ok());
Source

pub fn try_into_typed<R: ValueRepr>(self) -> Result<R::Value>

Moves into the concrete witness type after checking the entire descriptor.

  • Postcondition: Success preserves contained allocations and transfers ownership without cloning or running value destructors.
  • Complexity: O(n) witness construction and comparison for n type nodes, plus a move of the concrete representation.
§Errors

Returns an error on any identity or physical layout mismatch. The consumed original is then destroyed exactly once; no unrelated typed access occurs.

§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::Leaf};
assert_eq!(OwnedValue::new::<Leaf<i32>>(7)
    .try_into_typed::<Leaf<i32>>().unwrap(), 7);
Source

pub unsafe fn into_typed_bound<R: ValueRepr>(self) -> R::Value

Moves into an exact previously bound concrete representation.

§Safety

This owner’s complete descriptor must match R, not merely its carrier.

  • Complexity: O(s) for s representation bytes.
§Examples

Prefer Self::try_into_typed at checked host boundaries.

Source

pub fn try_clone(&self) -> Result<Self>

Clones through the frozen plan without consuming or mutating this value.

If a leaf clone panics, every completed cloned prefix is destroyed and its storage released; this original remains live.

  • Complexity: O(v) traversal time, O(d) call space, and storage for the cloned values, excluding leaf clone costs; v counts contained values.
§Errors

Returns an error before cloning anything if cloning is unavailable.

§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::{Leaf, ValueType}};
let original = OwnedValue::new::<Leaf<String>>(String::from("leaf"))
    .with_value_type(ValueType::cloneable_leaf::<String>()).unwrap();
assert_eq!(original.try_clone().unwrap()
    .try_into_typed::<Leaf<String>>().unwrap(), "leaf");
Source

pub fn try_eq(&self, other: &Self) -> Result<bool>

Compares same-shaped values through this owner’s independent equality plan.

The other owner’s capability configuration need not match this one’s.

  • Complexity: O(n + v) worst-case traversal time and O(d) call space, excluding leaf equality costs, for n type nodes and v contained values.
§Errors

Returns an error without invoking equality if shapes differ or this owner’s equality capability is absent. Neither owner is consumed.

§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::{Leaf, ValueType}};
let a = OwnedValue::new::<Leaf<i32>>(1)
    .with_value_type(ValueType::leaf::<i32>().with_equality::<Leaf<i32>>().unwrap())
    .unwrap();
assert!(a.try_eq(&OwnedValue::new::<Leaf<i32>>(1)).unwrap());
Source

pub fn try_debug(&self) -> Result<String>

Formats through the independent debug plan without consuming the value.

Structural arrays use brackets; tuples use parentheses in source order.

  • Complexity: O(v + s) time, O(d) call space, and O(s) output storage, excluding leaf formatting costs, for v values and s output bytes.
§Errors

Returns an error before formatting anything if debug support is absent.

§Examples
use cel_runtime::{owned_value::OwnedValue, value_type::{Leaf, ValueType}};
let owner = OwnedValue::new::<Leaf<i32>>(7)
    .with_value_type(ValueType::leaf::<i32>().with_debug::<Leaf<i32>>().unwrap())
    .unwrap();
assert_eq!(owner.try_debug().unwrap(), "7");
Source

pub fn as_ptr(&self) -> *const u8

Borrows the raw representation for trusted, already validated execution.

The pointer remains live only while this owner remains borrowed.

§Examples
let owner = cel_runtime::OwnedValue::new::<cel_runtime::Leaf<i32>>(1);
assert!(!owner.as_ptr().is_null());
Source

pub unsafe fn eq_bound(&self, other: &Self) -> bool

Compares values whose complete identity has already been bound by a host.

§Safety

Both owners must have exactly the same complete shape, and this owner’s descriptor must support equality.

  • Complexity: O(v) for v contained values, excluding leaf comparison costs.
§Examples

Use Self::try_eq at checked host boundaries.

Trait Implementations§

Source§

impl Drop for OwnedValue

Source§

fn drop(&mut self)

Destroys the live value before its allocation is automatically released.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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, 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.