Skip to main content

Function

Struct Function 

Source
pub struct Function<A: IVm>(/* private fields */);
Expand description

A function value: it can be called, it has a length, it has a text, and it has an identity. Nothing else. It holds a VM’s own value, laid out as Unpacked lays out every value, which the VM constructs through its own capability, such as IStaticFunction, and Function::new wraps.

Compared by identity, an Rc in naive: every construction is a new function, as JavaScript makes a new function of every evaluation of an arrow, and (() => 1) === (() => 1) is false. A built-in is no kind apart: it is a closure of the runtime value, vm::runtime, built once and read from the value, so Object.is === Object.is holds because both reads find the one closure, and its text is the NativeFunction text the compiled runtime gave it (fjs/js/runtime/README.md, “How NaNVM finds it”).

Implementations§

Source§

impl<A: IVm> Function<A>

Source

pub fn new(internal: A::InternalFunction) -> Self

Source

pub fn call(&self, args: Array<A>) -> Result<Any<A>, Any<A>>

Call the function with an arguments array. No user function reads this, so there is no receiver to pass.

Source

pub fn length(&self) -> u32

f.length.

Source

pub fn text(&self) -> Result<String<A>, Any<A>>

String(f): the text the function was given, or the refusal of a function without one (error::function_text).

Trait Implementations§

Source§

impl<A: Clone + IVm> Clone for Function<A>

Source§

fn clone(&self) -> Function<A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<A: IVm> Debug for Function<A>

A fixed marker: Debug is a Rust diagnostic, not a program value, so it carries no text a program could observe.

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<A: IVm> From<Function<A>> for Unpacked<A>

Source§

fn from(value: Function<A>) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> PartialEq for Function<A>

Identity: a function is its own value, by reference.

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<A: IVm> TryFrom<Any<A>> for Function<A>

Source§

type Error = Any<A>

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

fn try_from(value: Any<A>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<A> Freeze for Function<A>
where <A as IVm>::InternalFunction: Freeze,

§

impl<A> RefUnwindSafe for Function<A>

§

impl<A> Send for Function<A>
where <A as IVm>::InternalFunction: Send,

§

impl<A> Sync for Function<A>
where <A as IVm>::InternalFunction: Sync,

§

impl<A> Unpin for Function<A>
where <A as IVm>::InternalFunction: Unpin,

§

impl<A> UnsafeUnpin for Function<A>

§

impl<A> UnwindSafe for Function<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToAny for T

Source§

fn to_any<A: IVm>(self) -> Any<A>
where Self: Into<Unpacked<A>>,

Source§

impl<T> ToArray for T

Source§

fn to_array<A: IVm>(self) -> Array<A>
where Self: Sized + IntoIterator<Item = Any<A>>,

Source§

impl<T> ToObject for T

Source§

fn to_object<A: IVm>(self) -> Object<A>
where Self: Sized + IntoIterator<Item = Property<A>>,

Source§

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

Source§

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> ToString for T

Source§

fn try_to_string<A: IVm>(self) -> Result<String<A>, Any<A>>
where Self: Sized + IntoIterator<Item = Result<u16, Any<A>>>,

Source§

fn to_string<A: IVm>(self) -> String<A>
where Self: Sized + IntoIterator<Item = u16>,

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.