pub trait ValueLike<'v>: Eq + Copy + Debug + Default + Display + Serialize + CoerceKey<Value<'v>> + Freeze<Frozen = FrozenValue> + Allocative + ProvidesStaticType<'v> + Sealed + 'v {
    type String: StringValueLike<'v>;

    // Required methods
    fn to_value(self) -> Value<'v>;
    fn from_frozen_value(v: FrozenValue) -> Self;
    fn write_hash(self, hasher: &mut StarlarkHasher) -> Result<()>;
    fn collect_repr(self, collector: &mut String);
    fn equals(self, other: Value<'v>) -> Result<bool>;
    fn compare(self, other: Value<'v>) -> Result<Ordering>;
    fn downcast_ref<T: StarlarkValue<'v>>(self) -> Option<&'v T>;

    // Provided methods
    fn invoke(
        self,
        args: &Arguments<'v, '_>,
        eval: &mut Evaluator<'v, '_>
    ) -> Result<Value<'v>> { ... }
    fn get_hashed(self) -> Result<Hashed<Self>> { ... }
    fn collect_str(self, collector: &mut String) { ... }
    fn downcast_ref_err<T: StarlarkValue<'v>>(self) -> Result<&'v T> { ... }
}
Expand description

Abstract over Value and FrozenValue.

The methods on this trait are those required to implement containers, allowing implementations of ComplexValue to be agnostic of their contained type. For details about each function, see the documentation for Value, which provides the same functions (and more).

Required Associated Types§

source

type String: StringValueLike<'v>

StringValue or FrozenStringValue.

Required Methods§

source

fn to_value(self) -> Value<'v>

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

source

fn from_frozen_value(v: FrozenValue) -> Self

Convert from FrozenValue.

source

fn write_hash(self, hasher: &mut StarlarkHasher) -> Result<()>

Hash the value.

source

fn collect_repr(self, collector: &mut String)

repr(x).

source

fn equals(self, other: Value<'v>) -> Result<bool>

x == other.

This operation can only return error on stack overflow.

source

fn compare(self, other: Value<'v>) -> Result<Ordering>

x <=> other.

source

fn downcast_ref<T: StarlarkValue<'v>>(self) -> Option<&'v T>

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

Provided Methods§

source

fn invoke( self, args: &Arguments<'v, '_>, eval: &mut Evaluator<'v, '_> ) -> Result<Value<'v>>

Call this value as a function with given arguments.

source

fn get_hashed(self) -> Result<Hashed<Self>>

Get hash value.

source

fn collect_str(self, collector: &mut String)

str(x).

source

fn downcast_ref_err<T: StarlarkValue<'v>>(self) -> Result<&'v T>

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

Object Safety§

This trait is not object safe.

Implementors§