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 identifier of the ink! module.

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.

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 */
    }
}

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

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

We mainly implement this trait for ink! module to have a derived Spanned implementation for it.

Convert self directly into a TokenStream object. Read more

Convert self directly into a TokenStream object. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.