Skip to content

Resource should implement Display #202

@tdelabro

Description

@tdelabro
#[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions