refactor checkpoint
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
use super::*;
|
||||
|
||||
pub fn deserialize_json<'a, T: de::Deserialize<'a>>(
|
||||
arg: &'a str,
|
||||
) -> Result<T, super::VeilidAPIError> {
|
||||
serde_json::from_str(arg).map_err(|e| VeilidAPIError::ParseError {
|
||||
message: e.to_string(),
|
||||
value: String::new(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn deserialize_opt_json<T: de::DeserializeOwned>(
|
||||
arg: Option<String>,
|
||||
) -> Result<T, VeilidAPIError> {
|
||||
let arg = arg.ok_or_else(|| VeilidAPIError::ParseError {
|
||||
message: "invalid null string".to_owned(),
|
||||
value: String::new(),
|
||||
})?;
|
||||
deserialize_json(&arg)
|
||||
}
|
||||
|
||||
pub fn serialize_json<T: Serialize>(val: T) -> String {
|
||||
serde_json::to_string(&val).expect("failed to serialize json value")
|
||||
}
|
||||
Reference in New Issue
Block a user