Skip to main content

Closure

Struct Closure 

Source
pub struct Closure {
    pub is_async: bool,
    pub arity: usize,
    pub body: ClosureBody,
    pub module: Rc<str>,
    pub captures: Vec<(Rc<str>, Value)>,
}
Expand description

A closure captures its environment by value at creation time.

Fields§

§is_async: bool§arity: usize

How many parameters this closure declares.

The whole of its signature that anything outside the backend that built it asks for, and the reason it is a number rather than the parameter list it used to be. Every reader wanted a count: crate::builtins::Callable::arity answers out of this, Result.mapError reads it to decide whether to hand its callback the error it is replacing, and builtins::expect_callback refuses a callback of the wrong shape in one place rather than at every call site that needs the check. None of them wanted a name, a default, a type or a span, and issue #121 is where each was asked and answered.

It counts parameters, not arguments a call must supply: a defaulted or a variadic parameter is one of these like any other, which is what params.len() answered when this was a Vec<Param>.

§body: ClosureBody§module: Rc<str>

The module a closure body resolves names in.

§captures: Vec<(Rc<str>, Value)>

Trait Implementations§

Source§

impl Debug for Closure

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.