Skip to main content
Version: v0.35.0

FunctionDefinition

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

Methods

add_attribute

add_attribute
comptime fn add_attribute<let N: u32>(self, attribute: str<N>) {}

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

Adds an attribute to the function. 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.

body

body
comptime fn body(self) -> Expr {}

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

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
comptime fn has_named_attribute<let N: u32>(self, name: str<N>) -> bool {}

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

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

is_unconstrained

is_unconstrained
comptime fn is_unconstrained(self) -> bool {}

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

Returns true if this function is unconstrained.

module

module
comptime fn module(self) -> Module {}

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

Returns the module where the function is defined.

name

name
comptime fn name(self) -> Quoted {}

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

Returns the name of the function.

parameters

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

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

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

return_type

return_type
comptime fn return_type(self) -> Type {}

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

The return type of the function.

set_body

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

Source code: noir_stdlib/src/meta/function_def.nr#L43-L45

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
comptime fn set_parameters(self, parameters: [(Quoted, Type)]) {}

Source code: noir_stdlib/src/meta/function_def.nr#L48-L50

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
comptime fn set_return_type(self, return_type: Type) {}

Source code: noir_stdlib/src/meta/function_def.nr#L53-L55

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.

set_return_public

set_return_public
comptime fn set_return_public(self, public: bool) {}

Source code: noir_stdlib/src/meta/function_def.nr#L58-L60

Mutates the function's return visibility to public (if true is given) or private (if false is given). 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_unconstrained

set_unconstrained
comptime fn set_unconstrained(self, value: bool) {}

Source code: noir_stdlib/src/meta/function_def.nr#L63-L65

Mutates the function to be unconstrained (if true is given) or not (if false is given). 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.

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.