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
impl OwnedValue
Sourcepub fn prepare_debug(&self) -> Result<ValueFormatter>
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");Sourcepub fn into_fields(self) -> Result<Vec<Self>>
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);Sourcepub fn new<R: ValueRepr>(value: R::Value) -> Self
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"));Sourcepub fn value_type(&self) -> &ValueType
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>()));Sourcepub fn with_value_type(self, value_type: ValueType) -> Result<Self>
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());Sourcepub fn try_into_typed<R: ValueRepr>(self) -> Result<R::Value>
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);Sourcepub unsafe fn into_typed_bound<R: ValueRepr>(self) -> R::Value
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.
Sourcepub fn try_clone(&self) -> Result<Self>
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");Sourcepub fn try_eq(&self, other: &Self) -> Result<bool>
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());Sourcepub fn try_debug(&self) -> Result<String>
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");Sourcepub fn as_ptr(&self) -> *const u8
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());Sourcepub unsafe fn eq_bound(&self, other: &Self) -> bool
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.