iota_graphql_rpc/types/
datatype.rs1use async_graphql::*;
6
7use crate::types::{
8 move_enum::MoveEnum,
9 move_module::MoveModule,
10 move_struct::{MoveStruct, MoveStructTypeParameter},
11 open_move_type::MoveAbility,
12};
13
14#[derive(Interface)]
19#[graphql(
20 name = "IMoveDatatype",
21 field(
22 name = "module",
23 ty = "MoveModule",
24 desc = "The module that the datatype belongs to."
25 ),
26 field(name = "name", ty = "String", desc = "The name of the datatype."),
27 field(
28 name = "abilities",
29 ty = "Option<&Vec<MoveAbility>>",
30 desc = "The abilities of the datatype."
31 ),
32 field(
33 name = "type_parameters",
34 ty = "Option<&Vec<MoveStructTypeParameter>>",
35 desc = "The type parameters of the datatype."
36 )
37)]
38pub(crate) enum IMoveDatatype {
39 Datatype(MoveDatatype),
40 Struct(MoveStruct),
41 Enum(MoveEnum),
42}
43
44pub(crate) enum MoveDatatype {
45 Struct(MoveStruct),
46 Enum(MoveEnum),
47}
48
49#[Object]
53impl MoveDatatype {
54 async fn module(&self, ctx: &Context<'_>) -> Result<MoveModule> {
55 match self {
56 MoveDatatype::Struct(s) => s.module(ctx).await,
57 MoveDatatype::Enum(e) => e.module(ctx).await,
58 }
59 }
60
61 async fn name(&self, ctx: &Context<'_>) -> Result<&str> {
62 match self {
63 MoveDatatype::Struct(s) => s.name(ctx).await,
64 MoveDatatype::Enum(e) => e.name(ctx).await,
65 }
66 }
67
68 async fn abilities(&self, ctx: &Context<'_>) -> Result<Option<&Vec<MoveAbility>>> {
69 match self {
70 MoveDatatype::Struct(s) => s.abilities(ctx).await,
71 MoveDatatype::Enum(e) => e.abilities(ctx).await,
72 }
73 }
74
75 async fn type_parameters(
76 &self,
77 ctx: &Context<'_>,
78 ) -> Result<Option<&Vec<MoveStructTypeParameter>>> {
79 match self {
80 MoveDatatype::Struct(s) => s.type_parameters(ctx).await,
81 MoveDatatype::Enum(e) => e.type_parameters(ctx).await,
82 }
83 }
84
85 async fn as_move_enum(&self) -> Option<&MoveEnum> {
86 match self {
87 MoveDatatype::Enum(e) => Some(e),
88 _ => None,
89 }
90 }
91
92 async fn as_move_struct(&self) -> Option<&MoveStruct> {
93 match self {
94 MoveDatatype::Struct(s) => Some(s),
95 _ => None,
96 }
97 }
98}
99
100impl From<MoveStruct> for MoveDatatype {
101 fn from(value: MoveStruct) -> Self {
102 MoveDatatype::Struct(value)
103 }
104}
105
106impl From<MoveEnum> for MoveDatatype {
107 fn from(value: MoveEnum) -> Self {
108 MoveDatatype::Enum(value)
109 }
110}