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",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1306,6 +1307,17 @@ dependencies = [
|
||||||
"serde",
|
"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]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.8"
|
version = "0.10.8"
|
||||||
|
|
|
@ -45,6 +45,8 @@ tokio = { version = "1.35.1", features = [
|
||||||
"sync",
|
"sync",
|
||||||
] }
|
] }
|
||||||
futures = { version = "0.3.30", features = ["executor"] }
|
futures = { version = "0.3.30", features = ["executor"] }
|
||||||
|
serde = { version = "1.0.171", features = ["derive"] }
|
||||||
|
serde_json = "1.0.102"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "rs-basic"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow.workspace = true
|
||||||
chrono = { version = "0.4.26", features = ["serde"] }
|
chrono = { version = "0.4.26", features = ["serde"] }
|
||||||
serde = { version = "1.0.171", features = ["derive"] }
|
serde_json.workspace = true
|
||||||
serde_json = "1.0.102"
|
serde.workspace = true
|
||||||
|
serde_repr = "0.1.18"
|
||||||
|
|
|
@ -26,6 +26,16 @@ enum Color {
|
||||||
Red,
|
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<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let qux_source = r#"{
|
let qux_source = r#"{
|
||||||
"some Key": [1, 2, 3],
|
"some Key": [1, 2, 3],
|
||||||
|
@ -52,5 +62,11 @@ fn main() -> anyhow::Result<()> {
|
||||||
dbg!(&color);
|
dbg!(&color);
|
||||||
let color_str = serde_json::to_string(&color)?;
|
let color_str = serde_json::to_string(&color)?;
|
||||||
dbg!(&color_str);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue