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

Create a new None value.

Create a new boolean.

Create a new integer.

Turn a FrozenValue into a Value. See the safety warnings on OwnedFrozenValue.

Obtain the underlying FrozenValue from inside the Value, if it is one.

Is this value None.

Obtain the underlying numerical value, if it is one.

Obtain the underlying bool if it is a boolean.

Obtain the underlying int if it is an integer.

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.

Obtain the underlying str if it is a string.

Are two Values equal, looking at only their underlying pointer. This function is low-level and provides two guarantees.

  1. It is reflexive, the same Value passed as both arguments will result in true.
  2. If this function is true, then Value::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.

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:

  1. Calling it mulitple times on the same Value will return ValueIdentity that compare equal.
  2. If two [Value] have ValueIdentity that compare equal, then Value::ptr_eq and Value::equals will also consider them to be equal.

type(x).

bool(x).

int(x).

x[index].

x[start:stop:stride].

len(x).

other in x.

+x.

-x.

x - other.

x * other.

x % other.

x / other.

x // other.

x & other.

x | other.

x ^ other.

x << other.

x >> other.

Invoke self with given arguments.

Invoke a function with only positional arguments.

type(x).

Add two Values together. Will first try using radd, before falling back to add.

Convert a value to a FrozenValue using a supplied Freezer.

Implement the str() function - converts a string value to itself, otherwise uses repr().

Implement the repr() function.

Convert the value to JSON.

Return an error if the value or any contained value does not support conversion to JSON.

Forwards to StarlarkValue::set_at.

Return the contents of an iterable collection, as an owned vector.

Operate over an iterable for a value.

Produce an iterable from a value.

Get the Hashed version of this Value.

Are two values equal. If the values are of different types it will return false. It will only error if there is excessive recursion.

How are two values comparable. For values of different types will return Err.

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.

Call export_as on the underlying value, but only if the type is mutable. Otherwise, does nothing.

Return the attribute with the given name.

Like get_attr but return an error if the attribute is not available.

Query whether an attribute exists on a type. Should be equivalent to whether get_attr succeeds, but potentially more efficient.

Get a list of all the attributes this function supports, used to implement the dir() function.

Trait Implementations

Allocate the value on a heap and return a reference to the allocated value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

Compare self to key and return true if they are equal.

Compare self to key and return true if they are equal.

Compare self to key and return true if they are equal.

When type is frozen, it is frozen into this type.

Freeze a value. The frozen value must be equal to the original, and produce the same hash. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Same type as Self but with lifetimes dropped to 'static. Read more

Serialize this value into the given Serde serializer. Read more

Recursively “trace” the value. Read more

Description of values acceptable by unpack_value, e. g. list or str.

Given a Value, try and unpack it into the given type, which may involve some element of conversion. The heap argument is usually not required. Read more

Unpack value, but instead of None return error about incorrect argument type.

Unpack value, but instead of None return error about incorrect named argument type.

StringValue or FrozenStringValue.

Produce a Value regardless of the type you are starting with.

Get a reference to underlying data or None if contained object has different type than requested. Read more

repr(x).

Hash the value.

x == other. Read more

x <=> other.

Get referenced StarlarkValue a value as AnyLifetime.

Call this value as a function with given arguments.

Get hash value.

str(x).

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Must return the TypeId of Self but where the lifetimes are changed to 'static. Must be consistent with static_type_of. Read more

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

Get an ARef pointing at this type.

Try and get an ARef pointing at this type. Returns an Err if the type Self is a RefCell which is already mutably borrowed. Read more

Return the underlying RefCell if Self is one, otherwise None.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert between two equal types.

Convert between references to two equal types.

Convert between mutable references to two equal types.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.