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>
impl<'v, 'a> Arguments<'v, 'a>
sourcepub fn names_map(&self) -> Result<SmallMap<StringValue<'v>, Value<'v>>>
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.
sourcepub fn len(&self) -> Result<usize>
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
.
sourcepub fn names(&self) -> Result<Dict<'v>>
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.
sourcepub fn positions<'b>(
&'b self,
heap: &'v Heap
) -> Result<impl Iterator<Item = Value<'v>> + 'b>
pub fn positions<'b>( &'b self, heap: &'v Heap ) -> Result<impl Iterator<Item = Value<'v>> + 'b>
Unpack all positional parameters into an iterator.
sourcepub fn unpack_kwargs(&self) -> Result<Option<DictRef<'v>>>
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.
sourcepub fn unpack_kwargs_key(k: Value<'v>) -> Result<&'v str>
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
.
sourcepub fn no_positional_args(&self, heap: &'v Heap) -> Result<()>
pub fn no_positional_args(&self, heap: &'v Heap) -> Result<()>
Produce Err
if there are any positional arguments.
sourcepub fn no_named_args(&self) -> Result<()>
pub fn no_named_args(&self) -> Result<()>
Produce Err
if there are any named (i.e. non-positional) arguments.
sourcepub fn positional<const N: usize>(
&self,
heap: &'v Heap
) -> Result<[Value<'v>; N]>
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.
sourcepub fn optional<const REQUIRED: usize, const OPTIONAL: usize>(
&self,
heap: &'v Heap
) -> Result<([Value<'v>; REQUIRED], [Option<Value<'v>>; OPTIONAL])>
pub fn optional<const REQUIRED: usize, const OPTIONAL: usize>( &self, heap: &'v Heap ) -> Result<([Value<'v>; REQUIRED], [Option<Value<'v>>; OPTIONAL])>
source§impl Arguments<'_, '_>
impl Arguments<'_, '_>
sourcepub fn check_this<'v, T: UnpackValue<'v>>(this: Value<'v>) -> Result<T>
pub fn check_this<'v, T: UnpackValue<'v>>(this: Value<'v>) -> Result<T>
Utility for checking a this
parameter matches what you expect.
sourcepub fn check_required<'v, T: UnpackValue<'v>>(
name: &str,
x: Option<Value<'v>>
) -> Result<T>
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.
sourcepub fn check_optional<'v, T: UnpackValue<'v>>(
name: &str,
x: Option<Value<'v>>
) -> Result<Option<T>>
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.