pub struct NativeFunction { /* private fields */ }
Expand description

Starlark representation of native (Rust) functions.

Almost always created with #[starlark_module].

Implementations

Create a new NativeFunction from the Rust function which works directly on the parameters. The called function is responsible for validating the parameters are correct.

Create a new NativeFunction from the Rust function, plus the parameter specification.

A .type value, if one exists. Specified using #[starlark(type("the_type"))].

Trait Implementations

Allocate a value in the frozen heap and return a reference to the allocated value.

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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

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

Serialize this value into the given Serde serializer. Read more

Define the function type

Return a string describing the type of self, as returned by the type() function. Read more

Like get_type, but returns a reusable FrozenStringValue pointer to it. This function deliberately doesn’t take a heap, as it would not be performant to allocate a new value each time. Read more

Directly invoke a function. The number of named and names arguments are guaranteed to be equal. Read more

Return how much extra memory is consumed by this data type, in bytes, in addition to the direct size_of measurements. Used for profiling, so best effort rather than precise. Defaults to 0. Should not reported any memory held on to by a Value. Read more

Get an attribute for the current value as would be returned by dotted expression (i.e. a.attribute). Read more

Return a vector of string listing all attribute of the current value. Read more

Return structured documentation for self, if available.

Is this value a match for a named type. Usually returns true for values matching get_type, but might also work for subtypes it implements. Read more

Get the members associated with this type, accessible via this_type.x. These members will have dir/getattr/hasattr properly implemented, so it is the preferred way to go if possible. See MethodsStatic for an example of how to define this method. Read more

Return a string representation of self, as returned by the repr() function. Defaults to the Display instance - which should be fine for nearly all types. In many cases the repr() representation will also be a Starlark expression for creating the value. Read more

Invoked to print repr when a cycle is the object stack is detected.

Convert self to a boolean, as returned by the bool() function. The default implementation returns true. Read more

Convert self to a integer value, as returned by the int() function if the type is numeric (not for string). Works for int and bool (0 = false, 1 = true). Read more

Return a hash data for self to be used when self is placed as a key in a Dict. Return an Err if there is no hash for this value (e.g. list). Must be stable between frozen and non-frozen values. Read more

Compare self with other for equality. Should only return an error on excessive recursion. Read more

Compare self with other. This method returns a result of type Ordering, or an Err if the two types differ. Read more

Return the result of a[index] if a is indexable.

Extract a slice of the underlying object if the object is indexable. The result will be object between start and stop (both of them are added length() if negative and then clamped between 0 and length()). stride indicates the direction. Read more

Returns an iterable over the value of this container if this value holds an iterable container. Read more

Call a function with the same iterator as would be returned from iterate. The one advantage is that the iterator does not need to be allocated in a Box. If you implement this function you must also implement iterate, but the reverse is not true (this function has a sensible default). Read more

Returns the length of the value, if this value is a sequence.

Return true if an attribute of name attribute exists for the current value. Read more

Tell wether other is in the current value, if it is a container. Read more

Apply the + unary operator to the current value. Read more

Apply the - unary operator to the current value. Read more

Add with the arguments the other way around. Should return None to fall through to normal add. Read more

Add other to the current value. Pass both self and the Value form of self as original. Read more

Substract other from the current value. Read more

Multiply the current value with other. Read more

Divide the current value by other. Always results in a float value. Read more

Apply the percent operator between the current value and other. Usually used on strings, as per the Starlark spec. Read more

Floor division between the current value and other. Read more

Bitwise & operator.

Bitwise | operator. Read more

Bitwise ^ operator.

Bitwise << operator.

Bitwise >> operator.

Called when exporting a value under a specific name,

Set the value at index with the new value. Read more

Set the attribute named attribute of the current value to value (e.g. a.attribute = value). Read more

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

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.

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.