Struct starlark::values::Value[][src]

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.

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

Get a pointer to a AValue.

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.

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.

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.

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

This function panics if the Value is borrowed mutably.

In many cases you may wish to call FromValue instead, as that can get a non-frozen value from an underlying frozen 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. Returns a pair of a boolean and the value.

The type is AttrType::Method if the attribute was defined via StarlarkValue::get_methods and should be used as a signal that if the attribute is subsequently called, e.g. object.attribute(argument) then the object should be passed as the first argument to the function, e.g. object.attribute(object, argument).

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.

Methods that just forward to the underlying StarlarkValue.

Invoke a function with only positional arguments.

Trait Implementations

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.

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

This method tests for !=.

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. 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.

Performs the conversion.

Performs the conversion.

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)

recently added

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.