rust-embedded-community / serde-json-core

`serde-json` for `no_std` programs
Apache License 2.0
161 stars 59 forks source link

Parse enum structs #17

Closed ethanfrey closed 5 years ago

ethanfrey commented 5 years ago

This adds support for serializing and deserializing more complex structs as I use in my app. This does add some code-size unfortunately, but gives us the full expressiveness of serde-json.

It let's us handle structs like this:

pub enum ContractResult {
    Ok(Response),
    Err(String),
}

#[derive(Serialize, Deserialize, Default)]
pub struct Response {
    pub messages: Vec<CosmosMsg>,
    pub log: Option<String>,
    pub data: Option<String>,
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CosmosMsg {
    Send {
        from_address: String,
        to_address: String,
        amount: Vec<Coin>,
    },
    Contract {
        contract_addr: String,
        msg: String,
    },
    Opaque {
        data: String,
    },
}
ethanfrey commented 5 years ago

Oops again