1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! ink! entity traits for callables (i.e ink! constructors and ink! messages).

use super::{FromSyntax, IsInkFn};
use crate::tree::utils;
use crate::{InkArg, InkArgKind, Selector, SelectorArg};

/// Implemented by ink! entities that represent an ink! callable entity (i.e an ink! constructor or ink! message).
pub trait IsInkCallable: FromSyntax + IsInkFn {
    /// Returns the ink! payable argument (if any) for the ink! callable entity.
    fn payable_arg(&self) -> Option<InkArg> {
        utils::ink_arg_by_kind(self.syntax(), InkArgKind::Payable)
    }

    /// Returns the ink! selector argument (if any) for the ink! callable entity.
    fn selector_arg(&self) -> Option<SelectorArg> {
        utils::ink_arg_by_kind(self.syntax(), InkArgKind::Selector).and_then(SelectorArg::cast)
    }

    /// Returns the ink! default argument (if any) for the ink! callable entity.
    fn default_arg(&self) -> Option<InkArg> {
        utils::ink_arg_by_kind(self.syntax(), InkArgKind::Default)
    }

    /// Returns the composed selector for the ink! callable entity.
    fn composed_selector(&self) -> Option<Selector>
    where
        Self: Sized,
    {
        Selector::compose(self)
    }
}