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