- refactor (de)serialization to JSON/String
This commit is contained in:
parent
0e6d8104e6
commit
2c430758f1
2 changed files with 20 additions and 9 deletions
|
|
@ -10,7 +10,6 @@ env_logger = "0.11.3"
|
||||||
tokio = "1.37.0"
|
tokio = "1.37.0"
|
||||||
axum = "0.7.5"
|
axum = "0.7.5"
|
||||||
tower = "0.4.13"
|
tower = "0.4.13"
|
||||||
utoipa = "4.2.0"
|
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[workspace.lints.clippy]
|
||||||
uninlined_format_args = "warn"
|
uninlined_format_args = "warn"
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,16 @@ mod tests {
|
||||||
let result = add(2, 2);
|
let result = add(2, 2);
|
||||||
assert_eq!(result, 4);
|
assert_eq!(result, 4);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn print_serialized() {
|
||||||
|
let temp_secret = TempSecret { content: String::from("Hallo"), version: 12 };
|
||||||
|
let serialized = serialize_secret_json(&temp_secret);
|
||||||
|
println!("string serialized: {:?}", serialized);
|
||||||
|
let deserialized = deserialize_secret_struct(&serialized);
|
||||||
|
println!("Struct field from deserialized: {}", deserialized.content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use serde_json::Result;
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|
@ -22,12 +29,17 @@ pub struct TempSecret {
|
||||||
pub version: i64
|
pub version: i64
|
||||||
}
|
}
|
||||||
|
|
||||||
/// serialize secret to JSON byte vector
|
// /// serialize secret to JSON byte vector
|
||||||
pub fn serialize_secret_json(secret: &TempSecret) -> Result<Vec<u8>> {
|
// pub fn serialize_secret_json(secret: &TempSecret) -> Result<Vec<u8>> {
|
||||||
serde_json::to_vec(&secret)
|
// serde_json::to_vec(&secret)
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// serialize secret to JSON String
|
||||||
|
pub fn serialize_secret_json(secret: &TempSecret) -> String {
|
||||||
|
serde_json::to_string(&secret).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// deserialize JSON byte vector to secret
|
/// deserialize JSON String to secret
|
||||||
// pub fn deserialize_secret_struct(raw: &String) -> Result<TempSecret> {
|
pub fn deserialize_secret_struct(raw: &String) -> TempSecret{
|
||||||
// serde_json::from_str(raw)
|
serde_json::from_str(&raw).unwrap()
|
||||||
// }
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue