Trait FromStringOrInteger

Source
pub trait FromStringOrInteger: Sized {
    type Binary: Serialize + DeserializeOwned;
    type Integer: Serialize + DeserializeOwned;

    // Required methods
    fn from_binary(b: Self::Binary) -> Result<Self>;
    fn from_string(s: String) -> Result<Self>;
    fn from_integer(i: Self::Integer) -> Result<Self>;
    fn to_binary(&self) -> Result<Self::Binary>;
    fn to_string(&self) -> Result<String>;
}
Expand description

Types which can be deserialized from either integers or strings.

Some types can be represented as an integer or a string in human-readable formats like JSON or TOML. For example, 1 GWEI might be represented by the integer 1000000000 or the string "1 gwei". Such types can implement FromStringOrInteger and then use [impl_string_or_integer] to derive this user-friendly serialization.

These types are assumed to have an efficient representation as an integral type in Rust – Self::Binary – and will be serialized to and from this type when using a non-human-readable encoding. With human readable encodings, serialization is always to a string.

Required Associated Types§

Required Methods§

Source

fn from_binary(b: Self::Binary) -> Result<Self>

Source

fn from_string(s: String) -> Result<Self>

Source

fn from_integer(i: Self::Integer) -> Result<Self>

Source

fn to_binary(&self) -> Result<Self::Binary>

Source

fn to_string(&self) -> Result<String>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§