Struct ink_lang_ir::ItemMod [−][src]
pub struct ItemMod { /* fields omitted */ }
Expand description
The ink! module.
This is the root of all ink! smart contracts and is defined similarly to
a normal Rust module annotated with
#[ink::contract( /* optional configuration */ )]
attribute.
It contains ink! specific items as well as normal Rust items.
Example
// #[ink::contract] <-- this line belongs to the ink! configuration!
mod my_contract {
#[ink(storage)]
pub struct MyStorage {
/* storage fields */
}
#[ink(event)]
pub struct MyEvent {
/* event fields */
}
impl MyStorage {
#[ink(constructor)]
pub fn my_constructor() -> Self {
/* constructor initialization */
}
#[ink(message)]
pub fn my_message(&self) {
/* message statements */
}
}
}
Note
This type has been named after syn::ItemMod
and inherits all of the
fields that are required for inline module definitions.
Developer Note
Structurally the ink! Module
mirrors an inline Rust module, for example:
mod rust_module {
/* some Rust item definitions */
}
If the capabilities of an inline Rust module change we have to adjust for that.
Implementations
Returns the storage struct definition for this ink! module.
Note
The storage definition is the struct that has been annotated with
#[ink(storage)]
. This struct is required to be defined in the root
of the ink! inline module.
Panics
If zero or multiple #[ink(storage)]
annotated structs were found in
the ink! module. This can be expected to never happen since upon
construction of an ink! module it is asserted that exactly one
#[ink(storage)]
struct exists.
Returns all (ink! and non-ink! specific) item definitions of the ink! inline module.
pub fn impls(&self) -> IterItemImpls<'_>ⓘNotable traits for IterItemImpls<'a>impl<'a> Iterator for IterItemImpls<'a> type Item = &'a ItemImpl;
pub fn impls(&self) -> IterItemImpls<'_>ⓘNotable traits for IterItemImpls<'a>impl<'a> Iterator for IterItemImpls<'a> type Item = &'a ItemImpl;
impl<'a> Iterator for IterItemImpls<'a> type Item = &'a ItemImpl;
Returns an iterator yielding all ink! implementation blocks.
Note
An ink! implementation block can be either an inherent impl
block
directly defined for the contract’s storage struct if it includes at
least one #[ink(message)]
or #[ink(constructor)]
annotation, e.g.:
impl MyStorage {
#[ink(message)]
pub fn my_message(&self) {
/* message implementation */
}
}
Also an implementation block can be defined as a trait implementation
for the ink! storage struct using the #[ink(impl)]
annotation even
if none of its interior items have any ink! specific attributes on them,
e.g.:
#[ink(impl)]
impl MyStorage {
fn my_method(&self) -> i32 {
/* method implementation */
}
}
pub fn events(&self) -> IterEvents<'_>ⓘNotable traits for IterEvents<'a>impl<'a> Iterator for IterEvents<'a> type Item = &'a Event;
pub fn events(&self) -> IterEvents<'_>ⓘNotable traits for IterEvents<'a>impl<'a> Iterator for IterEvents<'a> type Item = &'a Event;
impl<'a> Iterator for IterEvents<'a> type Item = &'a Event;
Returns an iterator yielding all event definitions in this ink! module.
Returns all non-ink! attributes of the ink! module.
Returns the visibility of the ink! module.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ItemMod
impl UnwindSafe for ItemMod
Blanket Implementations
Mutably borrows from an owned value. Read more
Returns a Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty. Read more