Skip to main content
Version: v0.35.0

Module

std::meta::module contains methods on the built-in Module type which represents a module in the source program. Note that this type represents a module generally, it isn't limited to only mod my_submodule { ... } declarations in the source program.

Methods

add_item

add_item
comptime fn add_item(self, item: Quoted) {}

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

Adds a top-level item (a function, a struct, a global, etc.) to the module. Adding multiple items in one go is also valid if the Quoted value has multiple items in it.
Note that the items are type-checked as if they are inside the module they are being added to.

functions

functions
comptime fn functions(self) -> [FunctionDefinition] {}

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

Returns each function defined in the module.

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/module.nr#L8-L10

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

is_contract

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

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

true if this module is a contract module (was declared via contract foo { ... }).

name

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

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

Returns the name of the module.

structs

structs
comptime fn structs(self) -> [StructDefinition] {}

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

Returns each struct defined in the module.

Trait Implementations

impl Eq for Module
impl Hash for Module

Note that each module is assigned a unique ID internally and this is what is used for equality and hashing. So even modules with identical names and contents may not be equal in this sense if they were originally different items in the source program.