sway_core/language/parsed/declaration/
abi.rs

1use crate::{
2    decl_engine::parsed_id::ParsedDeclId,
3    engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext},
4    transform,
5};
6
7use super::{FunctionDeclaration, Supertrait, TraitItem};
8
9use sway_types::{ident::Ident, span::Span, Named, Spanned};
10
11/// An `abi` declaration, which declares an interface for a contract
12/// to implement or for a caller to use to call a contract.
13#[derive(Debug, Clone)]
14pub struct AbiDeclaration {
15    /// The name of the abi trait (also known as a "contract trait")
16    pub name: Ident,
17    /// The methods a contract is required to implement in order opt in to this interface
18    pub interface_surface: Vec<TraitItem>,
19    pub supertraits: Vec<Supertrait>,
20    /// The methods provided to a contract "for free" upon opting in to this interface
21    pub methods: Vec<ParsedDeclId<FunctionDeclaration>>,
22    pub(crate) span: Span,
23    pub attributes: transform::AttributesMap,
24}
25
26impl EqWithEngines for AbiDeclaration {}
27impl PartialEqWithEngines for AbiDeclaration {
28    fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
29        self.name == other.name
30            && self.interface_surface.eq(&other.interface_surface, ctx)
31            && self.supertraits.eq(&other.supertraits, ctx)
32            && PartialEqWithEngines::eq(&self.methods, &other.methods, ctx)
33            && self.span == other.span
34            && self.attributes == other.attributes
35    }
36}
37
38impl Named for AbiDeclaration {
39    fn name(&self) -> &sway_types::BaseIdent {
40        &self.name
41    }
42}
43
44impl Spanned for AbiDeclaration {
45    fn span(&self) -> sway_types::Span {
46        self.span.clone()
47    }
48}