Module starlark::values

source ·
Expand description

Defines a runtime Starlark value (Value) and traits for defining custom values (StarlarkValue).

This module contains code for working with Starlark values:

  • Most code dealing with Starlark will use Value, as it represents the fundamental values used in Starlark. When frozen, they become FrozenValue.
  • Values are garbage-collected, so a given Value lives on a Heap.
  • Rust values (e.g. String, Vec) can be added to the Heap with AllocValue, and deconstructed from a Value with UnpackValue (or specialised methods like unpack_str).
  • To define your own Rust data type that can live in a Value it must implement the StarlarkValue trait.
  • All the nested modules represent the built-in Starlark values. These are all defined using StarlarkValue, so may serve as interesting inspiration for writing your own values, in addition to occurring in Starlark programs.

Re-exports§

Modules§

  • A type StarlarkAny which can cheaply wrap any Rust value into a Value.
  • Array type used in implementation of List.
  • The boolean type (False and True).
  • The dictionary type, a mutable associative-map, which iterates in insertion order.
  • Fixed set enumerations, with runtime checking of validity.
  • Utilities for implementing StarlarkValue::export_as.
  • The floating point number type (3.14, 4e2).
  • Function types, including native functions and object.member functions.
  • The integer type.
  • The list type, a mutable sequence of values.
  • Utility for unpacking a value of type list[T] or tuple[T, ...] into a vec.
  • The None type.
  • The range type, constructed with range().
  • A record type, comprising of a fixed set of fields.
  • Convert a value implementing StarlarkValue into a type usable in type expression.
  • The string type. All strings must be valid UTF8.
  • The struct type, an associative-map created with struct().
  • The list type, an immutable sequence of values.
  • Trait and default implementations of a trait that will show starlark type annotations for a given type.
  • Typechecker-related types.

Macros§

  • Generate {has,get,dir}_attr in the StarlarkValue impl block that proxy to the ones generated by derive(StarlarkAttrs)

Structs§

Enums§

  • Common errors returned by Starlark evaluation.

Traits§

Type Aliases§

Attribute Macros§

  • Generate missing elements of StarlarkValue trait when this attribute is applied to an impl block of StarlarkValue.

Derive Macros§

  • Derive the Freeze trait.
  • Derive the NoSerialize trait for serde.
  • Derive the ProvidesStaticType trait. Requires the type has no type arguments, no constant arguments, and at most one lifetime argument.
  • Derive accessor methods that are designed to be used from {has,get,dir}_attr in an impl StarlarkValue block. All fields in the struct that are not marked with #[starlark(skip)] are exported to Starlark code as attributes. NOTE: Any usage must also call starlark_attrs!() in the impl block for StarlarkValue, otherwise the generated attr methods will not be used.
  • Derive the Trace trait.
  • Derive the UnpackValue trait.