Struct ink_lang_ir::ItemMod[][src]

pub struct ItemMod { /* fields omitted */ }

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

impl ItemMod[src]

pub fn ident(&self) -> &Ident[src]

Returns the identifier of the ink! module.

pub fn storage(&self) -> &Storage[src]

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.

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

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;
[src]

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;
[src]

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

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

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

pub fn vis(&self) -> &Visibility[src]

Returns the visibility of the ink! module.

Trait Implementations

impl Debug for ItemMod[src]

impl Eq for ItemMod[src]

impl PartialEq<ItemMod> for ItemMod[src]

impl StructuralEq for ItemMod[src]

impl StructuralPartialEq for ItemMod[src]

impl ToTokens for ItemMod[src]

fn to_tokens(&self, tokens: &mut TokenStream)[src]

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

impl TryFrom<ItemMod> for ItemMod[src]

type Error = Error

The type returned in the event of a conversion error.

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Spanned for T where
    T: Spanned + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.