Struct starlark::eval::Arguments

source ·
pub struct Arguments<'v, 'a>(/* private fields */);
Expand description

Arguments object is passed from the starlark interpreter to function implementation when evaluation function or method calls.

Implementations§

source§

impl<'v, 'a> Arguments<'v, 'a>

source

pub fn names_map(&self) -> Result<SmallMap<StringValue<'v>, Value<'v>>>

Unwrap all named arguments (both explicit and in **kwargs) into a map.

This operation fails if named argument names are not unique.

source

pub fn len(&self) -> Result<usize>

The number of arguments, where those inside a args/kwargs are counted as multiple arguments.

This operation fails if the kwargs is not a dictionary, or args does not support len.

source

pub fn names(&self) -> Result<Dict<'v>>

Unwrap all named arguments (both explicit and in **kwargs) into a dictionary.

This operation fails if named argument names are not unique.

source

pub fn positions<'b>( &'b self, heap: &'v Heap ) -> Result<impl Iterator<Item = Value<'v>> + 'b>

Unpack all positional parameters into an iterator.

source

pub fn unpack_kwargs(&self) -> Result<Option<DictRef<'v>>>

Examine the kwargs field, converting it to a Dict or failing. Note that even if this operation succeeds, the keys in the kwargs will not have been validated to be strings (as they must be). The arguments may also overlap with named, which would be an error.

source

pub fn unpack_kwargs_key(k: Value<'v>) -> Result<&'v str>

Confirm that a key in the kwargs field is indeed a string, or Err.

source

pub fn no_positional_args(&self, heap: &'v Heap) -> Result<()>

Produce Err if there are any positional arguments.

source

pub fn no_named_args(&self) -> Result<()>

Produce Err if there are any named (i.e. non-positional) arguments.

source

pub fn positional<const N: usize>( &self, heap: &'v Heap ) -> Result<[Value<'v>; N]>

Collect exactly N positional arguments from the Arguments, failing if there are too many/few arguments. Ignores named arguments.

source

pub fn optional<const REQUIRED: usize, const OPTIONAL: usize>( &self, heap: &'v Heap ) -> Result<([Value<'v>; REQUIRED], [Option<Value<'v>>; OPTIONAL])>

Collect exactly REQUIRED positional arguments, plus at most OPTIONAL positional arguments from the Arguments, failing if there are too many/few arguments. Ignores named arguments. The OPTIONAL array will never have a Some after a None.

source

pub fn positional1(&self, heap: &'v Heap) -> Result<Value<'v>>

Collect 1 positional arguments from the Arguments, failing if there are too many/few arguments. Ignores named arguments.

source

pub fn optional1(&self, heap: &'v Heap) -> Result<Option<Value<'v>>>

Collect up to 1 optional arguments from the Arguments, failing if there are too many arguments. Ignores named arguments.

source§

impl Arguments<'_, '_>

source

pub fn check_this<'v, T: UnpackValue<'v>>(this: Value<'v>) -> Result<T>

Utility for checking a this parameter matches what you expect.

source

pub fn check_required<'v, T: UnpackValue<'v>>( name: &str, x: Option<Value<'v>> ) -> Result<T>

Utility for checking a required parameter matches what you expect.

source

pub fn check_optional<'v, T: UnpackValue<'v>>( name: &str, x: Option<Value<'v>> ) -> Result<Option<T>>

Utility for checking an optional parameter matches what you expect.

Trait Implementations§

source§

impl<'v, 'a> Clone for Arguments<'v, 'a>

source§

fn clone(&self) -> Arguments<'v, 'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'v, 'a> Default for Arguments<'v, 'a>

source§

fn default() -> Arguments<'v, 'a>

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

impl<'v, 'a> Dupe for Arguments<'v, 'a>

source§

fn dupe(&self) -> Self

Auto Trait Implementations§

§

impl<'v, 'a> !RefUnwindSafe for Arguments<'v, 'a>

§

impl<'v, 'a> !Send for Arguments<'v, 'a>

§

impl<'v, 'a> !Sync for Arguments<'v, 'a>

§

impl<'v, 'a> Unpin for Arguments<'v, 'a>

§

impl<'v, 'a> !UnwindSafe for Arguments<'v, 'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.