ethabi_fork_ethcontract/
state_mutability.rs1use serde::de::{Error, Visitor};
2use serde::{Deserialize, Deserializer};
3use std::fmt;
4
5#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7pub enum StateMutability {
8 Pure,
10 View,
12 NonPayable,
14 Payable,
16}
17
18impl Default for StateMutability {
19 fn default() -> Self {
20 Self::NonPayable
21 }
22}
23
24impl<'a> Deserialize<'a> for StateMutability {
25 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
26 where
27 D: Deserializer<'a>,
28 {
29 deserializer.deserialize_any(StateMutabilityVisitor)
30 }
31}
32
33struct StateMutabilityVisitor;
34
35impl<'a> Visitor<'a> for StateMutabilityVisitor {
36 type Value = StateMutability;
37
38 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
39 write!(formatter, "the string 'pure', 'view', 'payable', or 'nonpayable'")
40 }
41
42 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
43 where
44 E: Error,
45 {
46 use StateMutability::*;
47 Ok(match v {
48 "pure" => Pure,
49 "view" => View,
50 "payable" => Payable,
51 "nonpayable" => NonPayable,
52 _ => return Err(Error::unknown_variant(v, &["pure", "view", "payable", "nonpayable"])),
53 })
54 }
55}