#[derive(
Clone, Copy, Debug, Deserialize, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[cfg_attr(
feature = "parity-scale-codec",
derive(parity_scale_codec::Encode, parity_scale_codec::Decode)
)]
#[cfg_attr(feature = "scale-info", derive(scale_info::TypeInfo))]
pub enum Resource {
#[serde(rename = "L1_GAS")]
L1Gas,
#[serde(rename = "L2_GAS")]
L2Gas,
}
The string "L1_GAS" and "L2_GAS" are defined by the protocol. Right now I have to define those myself while using this lib:
const L1_GAS: &[u8] = b"L1_GAS";
const L2_GAS: &[u8] = b"L2_GAS";
...
match resource {
Resource::L1Gas => L1_GAS,
Resource::L2Gas => L2_GAS,
}
This is error prove and unnecessary. starknet-api should provide a way for the lib consumers to access those values directly.
Display provides the to_string method, which seems like a good way to implement this. It could also be used in your serde(rename) tag, instead of hardcoding it.
The string
"L1_GAS"and"L2_GAS"are defined by the protocol. Right now I have to define those myself while using this lib:This is error prove and unnecessary. starknet-api should provide a way for the lib consumers to access those values directly.
Displayprovides theto_stringmethod, which seems like a good way to implement this. It could also be used in yourserde(rename)tag, instead of hardcoding it.