FunctionDefinition
std::meta::function_def contains methods on the built-in FunctionDefinition type representing
a function definition in the source program.
Methods
as_typed_expr
pub comptime fn as_typed_expr(self) -> TypedExpr {}
Returns this function as a TypedExpr, which can be unquoted. For example:
let typed_expr = some_function.as_typed_expr();
let _ = quote { $typed_expr(1, 2, 3); };
body
pub comptime fn body(self) -> Expr {}
Returns the body of the function as an expression. This is only valid on functions in the current crate which have not yet been resolved. This means any functions called at compile-time are invalid targets for this method.
disable
pub comptime fn disable(self, error_message: CtString) {}
Disables calling the given function, issuing an error with the provided message if it is ever called.
If an attribute generates a new version of a function that is meant to be called instead, calling disable
on the old function can be helpful to point a user to the new function to call.
If the disabled function is part of a contract, this function will also remove it from the contract
interface as if #[contract_library_method] was used.
This method requires the given function to yet be elaborated by the compiler - otherwise it is possible it is already called elsewhere without an error.
Security
Before switching over to use these newly generated functions, users should run nargo expand on any
untrusted dependencies to ensure their bodies are as expected.
has_named_attribute
pub comptime fn has_named_attribute<let N: u32>(self, name: str<N>) -> bool {}
Returns true if this function has a custom attribute with the given name.
is_unconstrained
pub comptime fn is_unconstrained(self) -> bool {}
Returns true if this function is unconstrained.
module
pub comptime fn module(self) -> Module {}
Returns the module where the function is defined.
name
pub comptime fn name(self) -> Quoted {}
Returns the name of the function.
parameters
pub comptime fn parameters(self) -> [(Quoted, Type)] {}
Returns each parameter of the function as a tuple of (parameter pattern, parameter type).
return_type
pub comptime fn return_type(self) -> Type {}
The return type of the function.
visibility
pub comptime fn visibility(self) -> Quoted {}
Returns the function's visibility as a Quoted value, which will be one of:
quote { }: the function is privatequote { pub }: the function ispubquote { pub(crate) }: the function ispub(crate)
Trait Implementations
impl Eq for FunctionDefinition
impl Hash for FunctionDefinition
Note that each function is assigned a unique ID internally and this is what is used for equality and hashing. So even functions with identical signatures and bodies may not be equal in this sense if they were originally different items in the source program.