Struct ink_lang_ir::ItemMod
source · [−]pub struct ItemMod { /* private fields */ }
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
sourceimpl ItemMod
impl ItemMod
sourcepub fn storage(&self) -> &Storage
pub fn storage(&self) -> &Storage
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.
sourcepub fn items(&self) -> &[Item]
pub fn items(&self) -> &[Item]
Returns all (ink! and non-ink! specific) item definitions of the ink! inline module.
sourcepub 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;
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 */
}
}
sourcepub 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;
Returns an iterator yielding all event definitions in this ink! module.
sourcepub fn vis(&self) -> &Visibility
pub fn vis(&self) -> &Visibility
Returns the visibility of the ink! module.
Trait Implementations
sourceimpl ToTokens for ItemMod
impl ToTokens for ItemMod
sourcefn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
We mainly implement this trait for ink! module to have a derived
Spanned
implementation for it.
sourcefn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
sourcefn into_token_stream(self) -> TokenStream
fn into_token_stream(self) -> TokenStream
impl Eq for ItemMod
impl StructuralEq for ItemMod
impl StructuralPartialEq for ItemMod
Auto Trait Implementations
impl RefUnwindSafe for ItemMod
impl !Send for ItemMod
impl !Sync for ItemMod
impl Unpin for ItemMod
impl UnwindSafe for ItemMod
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
sourcefn span(&self) -> Span
fn span(&self) -> Span
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty. Read more