pub struct Value<'v>(_);
Expand description
A Starlark value. The lifetime argument 'v
corresponds to the Heap
it is stored on.
Many of the methods simply forward to the underlying StarlarkValue
.
The Display
trait is equivalent to the repr()
function in Starlark.
Implementations
sourceimpl<'v> Value<'v>
impl<'v> Value<'v>
sourcepub fn new_frozen(x: FrozenValue) -> Self
pub fn new_frozen(x: FrozenValue) -> Self
Turn a FrozenValue
into a Value
. See the safety warnings on
OwnedFrozenValue
.
sourcepub fn unpack_frozen(self) -> Option<FrozenValue>
pub fn unpack_frozen(self) -> Option<FrozenValue>
Obtain the underlying FrozenValue
from inside the Value
, if it is one.
sourcepub fn unpack_num(self) -> Option<Num>
pub fn unpack_num(self) -> Option<Num>
Obtain the underlying numerical value, if it is one.
sourcepub fn unpack_bool(self) -> Option<bool>
pub fn unpack_bool(self) -> Option<bool>
Obtain the underlying bool
if it is a boolean.
sourcepub fn unpack_int(self) -> Option<i32>
pub fn unpack_int(self) -> Option<i32>
Obtain the underlying int
if it is an integer.
sourcepub fn unpack_starlark_str(self) -> Option<&'v StarlarkStr>
pub fn unpack_starlark_str(self) -> Option<&'v StarlarkStr>
Like unpack_str
, but gives a pointer to a boxed string.
Mostly useful for when you want to convert the string to a dyn
trait, but can’t
form a dyn
of an unsized type.
Unstable and likely to be removed in future, as the presence of the Box
is
not a guaranteed part of the API.
sourcepub fn unpack_str(self) -> Option<&'v str>
pub fn unpack_str(self) -> Option<&'v str>
Obtain the underlying str
if it is a string.
sourcepub fn ptr_eq(self, other: Self) -> bool
pub fn ptr_eq(self, other: Self) -> bool
Are two Value
s equal, looking at only their underlying pointer. This function is
low-level and provides two guarantees.
- It is reflexive, the same
Value
passed as both arguments will result intrue
. - If this function is
true
, thenValue::equals
will also consider them equal.
Note that other properties are not guaranteed, and the result is not considered part of the API. The result can be impacted by optimisations such as hash-consing, copy-on-write, partial evaluation etc.
sourcepub fn identity(self) -> ValueIdentity<'v>
pub fn identity(self) -> ValueIdentity<'v>
Returns an identity for this Value
, derived from its pointer. This function is
low-level and provides two guarantees. Those are valid until the next GC:
- Calling it mulitple times on the same
Value
will returnValueIdentity
that compare equal. - If two [
Value]
haveValueIdentity
that compare equal, thenValue::ptr_eq
andValue::equals
will also consider them to be equal.
sourcepub fn slice(
self,
start: Option<Value<'v>>,
stop: Option<Value<'v>>,
stride: Option<Value<'v>>,
heap: &'v Heap
) -> Result<Value<'v>>
pub fn slice(
self,
start: Option<Value<'v>>,
stop: Option<Value<'v>>,
stride: Option<Value<'v>>,
heap: &'v Heap
) -> Result<Value<'v>>
x[start:stop:stride]
.
sourcepub fn left_shift(self, other: Value<'v>) -> Result<Value<'v>>
pub fn left_shift(self, other: Value<'v>) -> Result<Value<'v>>
x << other
.
sourcepub fn right_shift(self, other: Value<'v>) -> Result<Value<'v>>
pub fn right_shift(self, other: Value<'v>) -> Result<Value<'v>>
x >> other
.
sourcepub fn invoke(
self,
args: &Arguments<'v, '_>,
eval: &mut Evaluator<'v, '_>
) -> Result<Value<'v>>
pub fn invoke(
self,
args: &Arguments<'v, '_>,
eval: &mut Evaluator<'v, '_>
) -> Result<Value<'v>>
Invoke self with given arguments.
sourcepub fn invoke_pos(
self,
pos: &[Value<'v>],
eval: &mut Evaluator<'v, '_>
) -> Result<Value<'v>>
pub fn invoke_pos(
self,
pos: &[Value<'v>],
eval: &mut Evaluator<'v, '_>
) -> Result<Value<'v>>
Invoke a function with only positional arguments.
sourcepub fn get_type_value(self) -> FrozenStringValue
pub fn get_type_value(self) -> FrozenStringValue
type(x)
.
sourcepub fn freeze(self, freezer: &Freezer) -> Result<FrozenValue>
pub fn freeze(self, freezer: &Freezer) -> Result<FrozenValue>
Convert a value to a FrozenValue
using a supplied Freezer
.
sourcepub fn to_str(self) -> String
pub fn to_str(self) -> String
Implement the str()
function - converts a string value to itself,
otherwise uses repr()
.
sourcepub fn to_json(self) -> Result<String>
pub fn to_json(self) -> Result<String>
Convert the value to JSON.
Return an error if the value or any contained value does not support conversion to JSON.
sourcepub fn set_attr(self, attribute: &str, alloc_value: Value<'v>) -> Result<()>
pub fn set_attr(self, attribute: &str, alloc_value: Value<'v>) -> Result<()>
Forwards to StarlarkValue::set_attr
.
sourcepub fn set_at(self, index: Value<'v>, alloc_value: Value<'v>) -> Result<()>
pub fn set_at(self, index: Value<'v>, alloc_value: Value<'v>) -> Result<()>
Forwards to StarlarkValue::set_at
.
sourcepub fn documentation(self) -> Option<DocItem>
pub fn documentation(self) -> Option<DocItem>
Forwards to StarlarkValue::documentation
.
sourcepub fn iterate_collect(self, heap: &'v Heap) -> Result<Vec<Value<'v>>>
pub fn iterate_collect(self, heap: &'v Heap) -> Result<Vec<Value<'v>>>
Return the contents of an iterable collection, as an owned vector.
sourcepub fn with_iterator<T>(
self,
heap: &'v Heap,
f: impl FnMut(&mut dyn Iterator<Item = Value<'v>>) -> T
) -> Result<T>
pub fn with_iterator<T>(
self,
heap: &'v Heap,
f: impl FnMut(&mut dyn Iterator<Item = Value<'v>>) -> T
) -> Result<T>
Operate over an iterable for a value.
sourcepub fn iterate(
self,
heap: &'v Heap
) -> Result<Box<dyn Iterator<Item = Value<'v>> + 'v>>
pub fn iterate(
self,
heap: &'v Heap
) -> Result<Box<dyn Iterator<Item = Value<'v>> + 'v>>
Produce an iterable from a value.
sourcepub fn equals(self, other: Value<'v>) -> Result<bool>
pub fn equals(self, other: Value<'v>) -> Result<bool>
Are two values equal. If the values are of different types it will
return false
. It will only error if there is excessive recursion.
sourcepub fn compare(self, other: Value<'v>) -> Result<Ordering>
pub fn compare(self, other: Value<'v>) -> Result<Ordering>
How are two values comparable. For values of different types will return Err
.
sourcepub fn describe(self, name: &str) -> String
pub fn describe(self, name: &str) -> String
Describe the value, in order to get its metadata in a way that could be used
to generate prototypes, help information or whatever other descriptive text
is required.
Plan is to make this return a data type at some point in the future, possibly
move on to StarlarkValue
and include data from members.
sourcepub fn export_as(self, variable_name: &str, eval: &mut Evaluator<'v, '_>)
pub fn export_as(self, variable_name: &str, eval: &mut Evaluator<'v, '_>)
Call export_as
on the underlying value, but only if the type is mutable.
Otherwise, does nothing.
sourcepub fn get_attr(
self,
attribute: &str,
heap: &'v Heap
) -> Result<Option<Value<'v>>>
pub fn get_attr(
self,
attribute: &str,
heap: &'v Heap
) -> Result<Option<Value<'v>>>
Return the attribute with the given name.
sourcepub fn get_attr_error(
self,
attribute: &str,
heap: &'v Heap
) -> Result<Value<'v>>
pub fn get_attr_error(
self,
attribute: &str,
heap: &'v Heap
) -> Result<Value<'v>>
Like get_attr
but return an error if the attribute is not available.
Trait Implementations
sourceimpl<'v> AllocValue<'v> for Value<'v>
impl<'v> AllocValue<'v> for Value<'v>
sourcefn alloc_value(self, _heap: &'v Heap) -> Value<'v>
fn alloc_value(self, _heap: &'v Heap) -> Value<'v>
Allocate the value on a heap and return a reference to the allocated value. Read more
sourceimpl Equivalent<FrozenValue> for Value<'_>
impl Equivalent<FrozenValue> for Value<'_>
sourcefn equivalent(&self, key: &FrozenValue) -> bool
fn equivalent(&self, key: &FrozenValue) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl Equivalent<Value<'_>> for FrozenValue
impl Equivalent<Value<'_>> for FrozenValue
sourcefn equivalent(&self, key: &Value<'_>) -> bool
fn equivalent(&self, key: &Value<'_>) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<'v> Equivalent<Value<'v>> for ValueStr<'_>
impl<'v> Equivalent<Value<'v>> for ValueStr<'_>
sourcefn equivalent(&self, key: &Value<'v>) -> bool
fn equivalent(&self, key: &Value<'v>) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<'v> Freeze for Value<'v>
impl<'v> Freeze for Value<'v>
type Frozen = FrozenValue
type Frozen = FrozenValue
When type is frozen, it is frozen into this type.
sourceimpl<'v> ProvidesStaticType for Value<'v>
impl<'v> ProvidesStaticType for Value<'v>
type StaticType = Value<'static>
type StaticType = Value<'static>
Same type as Self
but with lifetimes dropped to 'static
. Read more
sourceimpl<'v> UnpackValue<'v> for Value<'v>
impl<'v> UnpackValue<'v> for Value<'v>
sourcefn unpack_value(value: Value<'v>) -> Option<Self>
fn unpack_value(value: Value<'v>) -> Option<Self>
sourcefn unpack_param(value: Value<'v>) -> Result<Self>
fn unpack_param(value: Value<'v>) -> Result<Self>
Unpack value, but instead of None
return error about incorrect argument type.
sourcefn unpack_named_param(value: Value<'v>, param_name: &str) -> Result<Self>
fn unpack_named_param(value: Value<'v>, param_name: &str) -> Result<Self>
Unpack value, but instead of None
return error about incorrect named argument type.
sourceimpl<'v> ValueLike<'v> for Value<'v>
impl<'v> ValueLike<'v> for Value<'v>
type String = StringValue<'v>
type String = StringValue<'v>
StringValue
or FrozenStringValue
.
sourcefn downcast_ref<T: StarlarkValue<'v>>(self) -> Option<&'v T>
fn downcast_ref<T: StarlarkValue<'v>>(self) -> Option<&'v T>
sourcefn collect_repr(self, collector: &mut String)
fn collect_repr(self, collector: &mut String)
repr(x)
.
sourcefn write_hash(self, hasher: &mut StarlarkHasher) -> Result<()>
fn write_hash(self, hasher: &mut StarlarkHasher) -> Result<()>
Hash the value.
sourcefn as_dyn_any(self) -> &'v dyn AnyLifetime<'v>
fn as_dyn_any(self) -> &'v dyn AnyLifetime<'v>
Get referenced StarlarkValue
a value as AnyLifetime
.
sourcefn invoke(
self,
args: &Arguments<'v, '_>,
eval: &mut Evaluator<'v, '_>
) -> Result<Value<'v>>
fn invoke(
self,
args: &Arguments<'v, '_>,
eval: &mut Evaluator<'v, '_>
) -> Result<Value<'v>>
Call this value as a function with given arguments.
sourcefn get_hashed(self) -> Result<Hashed<Self>>
fn get_hashed(self) -> Result<Hashed<Self>>
Get hash value.
sourcefn collect_str(self, collector: &mut String)
fn collect_str(self, collector: &mut String)
str(x)
.
impl<'v> Coerce<Value<'v>> for StringValue<'v>
impl<'v> Coerce<Value<'v>> for Value<'v>
impl<'v> Coerce<Value<'v>> for FrozenValue
impl<'v> CoerceKey<Value<'v>> for StringValue<'v>
impl<'v> CoerceKey<Value<'v>> for Value<'v>
impl<'v> CoerceKey<Value<'v>> for FrozenValue
impl<'v> Copy for Value<'v>
impl Eq for Value<'_>
Auto Trait Implementations
impl<'v> !RefUnwindSafe for Value<'v>
impl<'v> Send for Value<'v>
impl<'v> !Sync for Value<'v>
impl<'v> Unpin for Value<'v>
impl<'v> !UnwindSafe for Value<'v>
Blanket Implementations
sourceimpl<'a, T> AnyLifetime<'a> for T where
T: 'a + ProvidesStaticType + ?Sized,
impl<'a, T> AnyLifetime<'a> for T where
T: 'a + ProvidesStaticType + ?Sized,
sourcefn static_type_id() -> TypeId
fn static_type_id() -> TypeId
Must return the TypeId
of Self
but where the lifetimes are changed
to 'static
. Must be consistent with static_type_of
. Read more
sourcefn static_type_of(&self) -> TypeId
fn static_type_of(&self) -> TypeId
Must return the TypeId
of Self
but where the lifetimes are changed
to 'static
. Must be consistent with static_type_id
. Must not
consult the self
parameter in any way. Read more
sourceimpl<T> AsARef<T> for T where
T: ?Sized,
impl<T> AsARef<T> for T where
T: ?Sized,
sourcefn try_as_aref(this: &T) -> Result<ARef<'_, T>, BorrowError>
fn try_as_aref(this: &T) -> Result<ARef<'_, T>, BorrowError>
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Serialize for T where
T: Serialize + ?Sized,
impl<T> Serialize for T where
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more