Struct ink_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§

source§

impl ItemMod

source

pub fn ident(&self) -> &Ident

Returns the identifier of the ink! module.

source

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.

source

pub fn items(&self) -> &[Item]

Returns all (ink! and non-ink! specific) item definitions of the ink! inline module.

source

pub fn impls(&self) -> IterItemImpls<'_>

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

pub fn events(&self) -> IterEvents<'_>

Returns an iterator yielding all event definitions in this ink! module.

source

pub fn attrs(&self) -> &[Attribute]

Returns all non-ink! attributes of the ink! module.

source

pub fn vis(&self) -> &Visibility

Returns the visibility of the ink! module.

Trait Implementations§

source§

impl Debug for ItemMod

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq<ItemMod> for ItemMod

source§

fn eq(&self, other: &ItemMod) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToTokens for ItemMod

source§

fn to_tokens(&self, tokens: &mut TokenStream)

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

source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
source§

fn into_token_stream(self) -> TokenStreamwhere
    Self: Sized,

Convert self directly into a TokenStream object. Read more
source§

impl TryFrom<ItemMod> for ItemMod

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(module: ItemMod) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for ItemMod

source§

impl StructuralEq for ItemMod

source§

impl StructuralPartialEq for ItemMod

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> Spanned for Twhere
    T: Spanned + ?Sized,

source§

fn span(&self) -> Span

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

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.