pub struct StructMember {
pub name: String,
pub description: Option<String>,
pub ty: Type,
}Expand description
Struct member definition.
Fields§
§name: String§description: Option<String>§ty: TypeImplementations§
Source§impl StructMember
impl StructMember
Sourcepub fn new(name: &str, description: &str, ty: NamedCLType) -> Self
pub fn new(name: &str, description: &str, ty: NamedCLType) -> Self
Creates a new struct member.
Examples found in repository?
examples/dns.rs (line 32)
18fn enum_example_schema() -> ContractSchema {
19 ContractSchema {
20 casper_contract_schema_version: 1,
21 toolchain: String::from("rustc 1.73.0 (cc66ad468 2023-10-03)"),
22 contract_name: String::from("DNS"),
23 contract_version: String::from("0.1.3"),
24 authors: vec![],
25 repository: None,
26 homepage: None,
27 errors: vec![],
28 types: vec![
29 CustomType::Struct {
30 name: TypeName::new("IP::IPv6"),
31 description: None,
32 members: vec![StructMember::new("ip", "", NamedCLType::ByteArray(16))],
33 },
34 CustomType::Struct {
35 name: TypeName::new("IP::IPv6WithDescription"),
36 description: None,
37 members: vec![
38 StructMember::new("ip", "", NamedCLType::ByteArray(16)),
39 StructMember::new("description", "", NamedCLType::String),
40 ],
41 },
42 CustomType::Enum {
43 name: TypeName::new("IP"),
44 description: Some(String::from("IP address")),
45 variants: vec![
46 EnumVariant {
47 name: String::from("Unknown"),
48 description: None,
49 discriminant: 0,
50 ty: NamedCLType::Unit.into(),
51 },
52 EnumVariant {
53 name: String::from("IPv4"),
54 description: Some(String::from("IPv4 address")),
55 discriminant: 1,
56 ty: NamedCLType::ByteArray(4).into(),
57 },
58 EnumVariant {
59 name: String::from("IPv4WithDescription"),
60 description: Some(String::from("IPv4 address with description")),
61 discriminant: 2,
62 ty: NamedCLType::Tuple2([
63 Box::new(NamedCLType::ByteArray(4)),
64 Box::new(NamedCLType::String),
65 ])
66 .into(),
67 },
68 EnumVariant {
69 name: String::from("IPv6"),
70 description: Some(String::from("IPv6 address")),
71 discriminant: 3,
72 ty: NamedCLType::Custom("IP::IPv6".to_owned()).into(),
73 },
74 EnumVariant {
75 name: String::from("IPv6WithDescription"),
76 description: Some(String::from("IPv6 address with description")),
77 discriminant: 4,
78 ty: NamedCLType::Custom("IP::IPv6WithDescription".to_owned()).into(),
79 },
80 ],
81 },
82 CustomType::Struct {
83 name: TypeName::new("DNSRecord"),
84 description: Some(String::from("DNS record")),
85 members: vec![
86 StructMember::new("name", "Domain name", NamedCLType::String),
87 StructMember::new("ip", "", NamedCLType::Custom("IP".to_owned())),
88 ],
89 },
90 ],
91 entry_points: vec![
92 Entrypoint {
93 name: String::from("add_record"),
94 description: None,
95 is_mutable: true,
96 arguments: vec![
97 Argument::new("name", "", NamedCLType::String),
98 Argument::new("ip", "", NamedCLType::Custom("IP".to_owned())),
99 ],
100 return_ty: NamedCLType::Unit.into(),
101 is_contract_context: true,
102 access: Access::Public,
103 },
104 Entrypoint {
105 name: String::from("remove_record"),
106 description: Some(String::from("Remove a DNS record")),
107 is_mutable: true,
108 arguments: vec![
109 Argument::new("name", "", NamedCLType::String),
110 Argument::new("ip", "", NamedCLType::Custom("IP".to_owned())),
111 ],
112 return_ty: NamedCLType::Unit.into(),
113 is_contract_context: true,
114 access: Access::Groups(vec![String::from("admin"), String::from("moderator")]),
115 },
116 ],
117 events: vec![
118 Event::new("event_RecordAdded", "DNSRecord"),
119 Event::new("event_RecordRemoved", "DNSRecord"),
120 ],
121 call: None,
122 }
123}More examples
examples/erc20.rs (lines 31-35)
3pub fn example_erc20_schema() -> ContractSchema {
4 ContractSchema {
5 casper_contract_schema_version: 1,
6 toolchain: String::from("rustc 1.73.0 (cc66ad468 2023-10-03)"),
7 contract_name: String::from("Erc20"),
8 contract_version: String::from("0.1.0"),
9 authors: vec![String::from("John Doe <john@doe.com>")],
10 repository: Some(String::from(
11 "https://github.com/casper-ecosystem/casper-contract-schema",
12 )),
13 homepage: Some(String::from("https://john.doe.com")),
14 errors: vec![
15 UserError {
16 name: String::from("InsufficientFunds"),
17 description: Some(String::from("Insufficient funds")),
18 discriminant: 100u16,
19 },
20 UserError {
21 name: String::from("InsufficientAllowance"),
22 description: Some(String::from("Insufficient allowance")),
23 discriminant: 101u16,
24 },
25 ],
26 types: vec![
27 CustomType::Struct {
28 name: TypeName::new("Transfer"),
29 description: Some(String::from("Transfer event")),
30 members: vec![
31 StructMember::new(
32 "from",
33 "Sender of tokens.",
34 NamedCLType::Option(Box::new(NamedCLType::Key)),
35 ),
36 StructMember::new(
37 "to",
38 "Recipient of tokens.",
39 NamedCLType::Option(Box::new(NamedCLType::Key)),
40 ),
41 StructMember::new("value", "Transfered amount.", NamedCLType::U256),
42 ],
43 },
44 CustomType::Struct {
45 name: TypeName::new("Approval"),
46 description: Some(String::from("Approval event")),
47 members: vec![
48 StructMember::new("owner", "", NamedCLType::Option(Box::new(NamedCLType::Key))),
49 StructMember::new(
50 "spender",
51 "",
52 NamedCLType::Option(Box::new(NamedCLType::Key)),
53 ),
54 StructMember::new("value", "", NamedCLType::U256),
55 ],
56 },
57 ],
58 entry_points: vec![
59 Entrypoint {
60 name: String::from("transfer"),
61 description: Some(String::from("Transfer tokens to another account")),
62 is_mutable: true,
63 arguments: vec![
64 Argument::new("recipient", "", NamedCLType::Key),
65 Argument::new("amount", "", NamedCLType::U256),
66 ],
67 return_ty: NamedCLType::Unit.into(),
68 is_contract_context: true,
69 access: Access::Public,
70 },
71 Entrypoint {
72 name: String::from("transfer_from"),
73 description: Some(String::from("Transfer tokens from one account to another")),
74 is_mutable: true,
75 arguments: vec![
76 Argument::new("owner", "", NamedCLType::Key),
77 Argument::new("recipient", "", NamedCLType::Key),
78 Argument::new("amount", "", NamedCLType::U256),
79 ],
80 return_ty: NamedCLType::Unit.into(),
81 is_contract_context: true,
82 access: Access::Public,
83 },
84 Entrypoint {
85 name: String::from("approve"),
86 description: Some(String::from(
87 "Approve spender to use tokens on behalf of the owner",
88 )),
89 is_mutable: true,
90 arguments: vec![
91 Argument::new("spender", "", NamedCLType::Key),
92 Argument::new("amount", "", NamedCLType::U256),
93 ],
94 return_ty: NamedCLType::Unit.into(),
95 is_contract_context: true,
96 access: Access::Public,
97 },
98 Entrypoint {
99 name: String::from("allowance"),
100 description: Some(String::from(
101 "Check the amount of tokens that an owner allowed to a spender",
102 )),
103 is_mutable: false,
104 arguments: vec![
105 Argument::new("owner", "", NamedCLType::Key),
106 Argument::new("spender", "", NamedCLType::Key),
107 ],
108 return_ty: NamedCLType::U256.into(),
109 is_contract_context: true,
110 access: Access::Public,
111 },
112 Entrypoint {
113 name: String::from("balance_of"),
114 description: Some(String::from(
115 "Check the amount of tokens owned by an account",
116 )),
117 is_mutable: false,
118 arguments: vec![Argument::new("owner", "", NamedCLType::Key)],
119 return_ty: NamedCLType::U256.into(),
120 is_contract_context: true,
121 access: Access::Public,
122 },
123 Entrypoint {
124 name: String::from("total_supply"),
125 description: Some(String::from("Check the total supply of tokens")),
126 is_mutable: false,
127 arguments: vec![],
128 return_ty: NamedCLType::U256.into(),
129 is_contract_context: true,
130 access: Access::Public,
131 },
132 ],
133 events: vec![
134 Event::new("event_Transfer", "Transfer"),
135 Event::new("event_Approval", "Approval"),
136 ],
137 call: Some(CallMethod::new(
138 "erc20.wasm",
139 "Fungible token",
140 vec![
141 Argument::new("name", "Name of the token", NamedCLType::String),
142 Argument::new("symbol", "Symbol of the token", NamedCLType::String),
143 Argument::new("decimals", "Number of decimals", NamedCLType::U8),
144 Argument::new(
145 "initial_supply",
146 "Initial supply of tokens",
147 NamedCLType::U256,
148 ),
149 ],
150 )),
151 }
152}Trait Implementations§
Source§impl Clone for StructMember
impl Clone for StructMember
Source§fn clone(&self) -> StructMember
fn clone(&self) -> StructMember
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StructMember
impl Debug for StructMember
Source§impl<'de> Deserialize<'de> for StructMember
impl<'de> Deserialize<'de> for StructMember
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for StructMember
impl Hash for StructMember
Source§impl JsonSchema for StructMember
impl JsonSchema for StructMember
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§fn always_inline_schema() -> bool
fn always_inline_schema() -> bool
👎Deprecated: Use
inline_schema() insteadOnly included for backward-compatibility - use
inline_schema() instead“. Read moreSource§impl Ord for StructMember
impl Ord for StructMember
Source§fn cmp(&self, other: &StructMember) -> Ordering
fn cmp(&self, other: &StructMember) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for StructMember
impl PartialEq for StructMember
Source§impl PartialOrd for StructMember
impl PartialOrd for StructMember
Source§impl Serialize for StructMember
impl Serialize for StructMember
impl Eq for StructMember
impl StructuralPartialEq for StructMember
Auto Trait Implementations§
impl Freeze for StructMember
impl RefUnwindSafe for StructMember
impl Send for StructMember
impl Sync for StructMember
impl Unpin for StructMember
impl UnwindSafe for StructMember
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more