repr enum serde
cargo devel CI / cargo CI (push) Successful in 1m52s
Details
cargo devel CI / cargo CI (push) Successful in 1m52s
Details
This commit is contained in:
parent
1e6f98595b
commit
e60b3021b0
|
@ -1282,6 +1282,7 @@ dependencies = [
|
|||
"chrono",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1306,6 +1307,17 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_repr"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
|
|
|
@ -45,6 +45,8 @@ tokio = { version = "1.35.1", features = [
|
|||
"sync",
|
||||
] }
|
||||
futures = { version = "0.3.30", features = ["executor"] }
|
||||
serde = { version = "1.0.171", features = ["derive"] }
|
||||
serde_json = "1.0.102"
|
||||
|
||||
[package]
|
||||
name = "rs-basic"
|
||||
|
|
|
@ -6,7 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.79"
|
||||
anyhow.workspace = true
|
||||
chrono = { version = "0.4.26", features = ["serde"] }
|
||||
serde = { version = "1.0.171", features = ["derive"] }
|
||||
serde_json = "1.0.102"
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
serde_repr = "0.1.18"
|
||||
|
|
|
@ -26,6 +26,16 @@ enum Color {
|
|||
Red,
|
||||
}
|
||||
|
||||
use serde_repr::{Serialize_repr, Deserialize_repr};
|
||||
|
||||
#[derive(Serialize_repr, Deserialize_repr, Clone, Debug, PartialEq)]
|
||||
#[repr(u8)]
|
||||
enum CLike {
|
||||
Amida = 1,
|
||||
Yamda = 2,
|
||||
Omaba = 10,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let qux_source = r#"{
|
||||
"some Key": [1, 2, 3],
|
||||
|
@ -52,5 +62,11 @@ fn main() -> anyhow::Result<()> {
|
|||
dbg!(&color);
|
||||
let color_str = serde_json::to_string(&color)?;
|
||||
dbg!(&color_str);
|
||||
|
||||
let cl = CLike::Omaba;
|
||||
let clrepr = serde_json::to_string(&cl)?;
|
||||
dbg!(&clrepr);
|
||||
let cl_from = serde_json::from_str(&clrepr)?;
|
||||
dbg!(cl == cl_from);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue