pub struct Function<S> {
pub name: String,
pub body: Rc<dyn FunctionBodyObject<S>>,
pub origin: Location,
pub read_only_location: Option<Location>,
}Expand description
Definition of a function.
Fields§
§name: StringString that identifies the function.
body: Rc<dyn FunctionBodyObject<S>>Command that is executed when the function is called.
This is wrapped in Rc so that we don’t have to clone the entire
command when we define a function. The function definition command only
clones the Rc object from the abstract syntax tree to create a
Function object.
origin: LocationLocation of the function definition command that defined this function.
read_only_location: Option<Location>Optional location where this function was made read-only.
If this function is not read-only, read_only_location is None.
Otherwise, read_only_location is the location of the simple command
that executed the readonly built-in that made this function read-only.
Implementations§
Source§impl<S> Function<S>
impl<S> Function<S>
Sourcepub fn new<N: Into<String>, B: Into<Rc<dyn FunctionBodyObject<S>>>>(
name: N,
body: B,
origin: Location,
) -> Self
pub fn new<N: Into<String>, B: Into<Rc<dyn FunctionBodyObject<S>>>>( name: N, body: B, origin: Location, ) -> Self
Creates a new function.
This is a convenience function for constructing a Function object.
The read_only_location is set to None.
Sourcepub fn make_read_only(self, location: Location) -> Self
pub fn make_read_only(self, location: Location) -> Self
Makes the function read-only.
This is a convenience function for doing
self.read_only_location = Some(location) in a method chain.
Sourcepub const fn is_read_only(&self) -> bool
pub const fn is_read_only(&self) -> bool
Whether this function is read-only or not.
Trait Implementations§
Source§impl<S> PartialEq for Function<S>
Compares two functions for equality.
impl<S> PartialEq for Function<S>
Compares two functions for equality.
Two functions are considered equal if all their members are equal.
This includes comparing the body members by pointer equality.
impl<S> Eq for Function<S>
Auto Trait Implementations§
impl<S> Freeze for Function<S>
impl<S> !RefUnwindSafe for Function<S>
impl<S> !Send for Function<S>
impl<S> !Sync for Function<S>
impl<S> Unpin for Function<S>
impl<S> !UnwindSafe for Function<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more