Data can now optionally have Serialize and Deserialize when 'serde' feature is enabled.
@@ -113,10 +113,31 @@ version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
+[[package]]
+name = "serde"
+version = "1.0.210"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
+dependencies = [
+ "serde_derive",
+]
+
+name = "serde_derive"
+checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
+ "proc-macro2",
+ "quote",
+ "syn",
[[package]]
name = "shared"
version = "0.1.1"
dependencies = [
+ "serde",
"tokio",
]
@@ -5,6 +5,8 @@ edition = "2021"
[features]
cast_into = []
+serde = ["dep:serde"]
[dependencies]
tokio = { version = "1.40.0", features = ["macros", "rt", "rt-multi-thread", "sync", "time"] }
+serde = { version = "1.0", features = ["derive"], optional = true}
@@ -2,6 +2,7 @@ use std::{collections::HashMap, fmt::Display, slice::{SliceIndex, Iter, IterMut}
use crate::Shared;
+#[cfg(not(feature = "serde"))]
#[derive(Debug, PartialEq, Clone)]
pub enum Data {
None,
@@ -23,6 +24,28 @@ pub enum Data {
Map(HashMap<String, Data>),
}
+#[cfg(feature="serde")]
+#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
+pub enum Data {
+ None,
+ String(String),
+ I8(i8),
+ I16(i16),
+ I32(i32),
+ I64(i64),
+ I128(i128),
+ U8(u8),
+ U16(u16),
+ U32(u32),
+ U64(u64),
+ U128(u128),
+ F32(f32),
+ F64(f64),
+ Bool(bool),
+ Vec(Vec<Data>),
+ Map(HashMap<String, Data>),
+}
impl Default for Data {
fn default() -> Self {
Self::None