pub struct OwnedFrozenValue { /* private fields */ }
Expand description

A FrozenValue along with a FrozenHeapRef that ensures it is kept alive. Obtained from FrozenModule::get or OwnedFrozenValue::alloc.

While it is possible to obtain the underlying FrozenValue with unchecked_frozen_value, that approach is strongly discouraged. See the other methods which unpack the code, access it as a Value (which has a suitable lifetime) or add references to other heaps.

Implementations§

source§

impl OwnedFrozenValue

source

pub unsafe fn new(owner: FrozenHeapRef, value: FrozenValue) -> Self

Create an OwnedFrozenValue - generally OwnedFrozenValues are obtained from FrozenModule::get. Safe provided the value (and any values it points at) are kept alive by the owner, typically because the value was created on the heap.

use starlark::values::FrozenHeap;
use starlark::values::OwnedFrozenValue;
let heap = FrozenHeap::new();
let value = heap.alloc("test");
unsafe { OwnedFrozenValue::new(heap.into_ref(), value) };
source

pub fn alloc(x: impl AllocFrozenValue) -> Self

Create an OwnedFrozenValue in a new heap.

source

pub fn unpack_bool(&self) -> Option<bool>

Unpack the boolean contained in the underlying value, or None if it is not a boolean.

source

pub fn unpack_i32(&self) -> Option<i32>

Obtain the underlying integer if it fits in an i32. Note floats are not considered integers, i. e. unpack_i32 for 1.0 will return None.

source

pub fn unpack_str(&self) -> Option<&str>

Unpack the string contained in the underlying value, or None if it is not an string.

source

pub fn downcast<T: StarlarkValue<'static>>( self ) -> Result<OwnedFrozenValueTyped<T>, Self>

Check if self references <T>.

source

pub fn downcast_anyhow<T: StarlarkValue<'static>>( self ) -> Result<OwnedFrozenValueTyped<T>>

downcast, but return an error for human instead of original value.

source

pub fn value<'v>(&'v self) -> Value<'v>

Obtain the Value stored inside.

source

pub fn owned_value<'v>(&self, heap: &'v FrozenHeap) -> Value<'v>

Extract a Value by passing the FrozenHeap which will promise to keep it alive. When using with a Module, see the frozen_heap function. If you don’t care about the resulting lifetime the value method is easier.

source

pub fn map(&self, f: impl FnOnce(FrozenValue) -> FrozenValue) -> Self

Operate on the FrozenValue stored inside. Safe provided you don’t store the argument FrozenValue after the closure has returned. Using this function is discouraged when possible.

source

pub fn try_map<E>( &self, f: impl FnOnce(FrozenValue) -> Result<FrozenValue, E> ) -> Result<Self, E>

Same as map above but with Result

source

pub fn owner(&self) -> &FrozenHeapRef

Obtain a reference to the FrozenHeap that owns this value.

source

pub unsafe fn unchecked_frozen_value(&self) -> FrozenValue

Obtain direct access to the FrozenValue that lives inside. If you drop all references to the FrozenHeap keeping it alive, any code using the FrozenValue is likely to segfault. If possible use value or owned_frozen_value.

source

pub unsafe fn owned_frozen_value(&self, heap: &FrozenHeap) -> FrozenValue

Extract a FrozenValue by passing the FrozenHeap which will keep it alive. Provided the argument heap does indeed stay alive for the lifetime of the result, all will be fine. Unsafe if you pass the wrong heap, or don’t keep the heap alive long enough. Where possible, use value or owned_value.

Trait Implementations§

source§

impl AllocFrozenValue for OwnedFrozenValue

source§

fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue

Allocate a value in the frozen heap and return a reference to the allocated value.
source§

impl Allocative for OwnedFrozenValue

source§

fn visit<'allocative_a, 'allocative_b: 'allocative_a>( &self, visitor: &'allocative_a mut Visitor<'allocative_b> )

source§

impl Clone for OwnedFrozenValue

source§

fn clone(&self) -> OwnedFrozenValue

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OwnedFrozenValue

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for OwnedFrozenValue

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for OwnedFrozenValue

source§

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

Formats the value using the given formatter. Read more
source§

impl Dupe for OwnedFrozenValue

source§

fn dupe(&self) -> Self

source§

impl StarlarkTypeRepr for OwnedFrozenValue

source§

fn starlark_type_repr() -> Ty

The representation of a type that a user would use verbatim in starlark type annotations

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> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

source§

impl<T> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.