Skip to main content
Version: dev

FunctionDefinition

std::meta::function_def contains methods on the built-in FunctionDefinition type representing a function definition in the source program.

Methods

body

body
fn body(self) -> Expr {}

Source code: noir_stdlib/src/meta/function_def.nr#L3-L5

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.

has_named_attribute

has_named_attribute
fn has_named_attribute(self, name: Quoted) -> bool {}

Source code: noir_stdlib/src/meta/function_def.nr#L8-L10

Returns true if this function has a custom attribute with the given name.

name

name
fn name(self) -> Quoted {}

Source code: noir_stdlib/src/meta/function_def.nr#L13-L15

Returns the name of the function.

parameters

parameters
fn parameters(self) -> [(Quoted, Type)] {}

Source code: noir_stdlib/src/meta/function_def.nr#L18-L20

Returns each parameter of the function as a tuple of (parameter pattern, parameter type).

return_type

return_type
fn return_type(self) -> Type {}

Source code: noir_stdlib/src/meta/function_def.nr#L23-L25

The return type of the function.

set_body

set_body
fn set_body(self, body: Expr) {}

Source code: noir_stdlib/src/meta/function_def.nr#L28-L30

Mutate the function body to a new 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.

set_parameters

set_parameters
fn set_parameters(self, parameters: [(Quoted, Type)]) {}

Source code: noir_stdlib/src/meta/function_def.nr#L33-L35

Mutates the function's parameters to a new set of parameters. 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.

Expects a slice of (parameter pattern, parameter type) for each parameter. Requires each parameter pattern to be a syntactically valid parameter.

set_return_type

set_return_type
fn set_return_type(self, return_type: Type) {}

Source code: noir_stdlib/src/meta/function_def.nr#L38-L40

Mutates the function's return type to a new type. 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.