TypeName

Struct TypeName 

Source
pub struct TypeName(pub String);
Expand description

Custom type name definition.

Tuple Fields§

§0: String

Implementations§

Source§

impl TypeName

Source

pub fn new(name: &str) -> Self

Creates a new type name.

Examples found in repository?
examples/dns.rs (line 30)
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
Hide additional examples
examples/erc20.rs (line 28)
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 TypeName

Source§

fn clone(&self) -> TypeName

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TypeName

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TypeName

Source§

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 From<&str> for TypeName

Source§

fn from(name: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for TypeName

Source§

fn from(name: String) -> Self

Converts to this type from the input type.
Source§

impl Hash for TypeName

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl JsonSchema for TypeName

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

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

Generates a JSON Schema for this type. Read more
Source§

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 more
Source§

fn always_inline_schema() -> bool

👎Deprecated: Use inline_schema() instead
Only included for backward-compatibility - use inline_schema() instead“. Read more
Source§

impl Ord for TypeName

Source§

fn cmp(&self, other: &TypeName) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TypeName

Source§

fn eq(&self, other: &TypeName) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TypeName

Source§

fn partial_cmp(&self, other: &TypeName) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for TypeName

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for TypeName

Source§

impl StructuralPartialEq for TypeName

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,