Initial public release of Warp.
Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use crate::{cloud_object::JsonObjectType, server::sync_queue::SerializedModel};
|
||||
|
||||
use super::generic_string_model::{Serializer, StringModel};
|
||||
|
||||
/// A `JsonModel` is a string model that can be serialized to and deserialized from JSON.
|
||||
pub trait JsonModel: StringModel + Serialize + DeserializeOwned + 'static {
|
||||
/// Returns the JsonObjectType for this model.
|
||||
fn json_object_type() -> JsonObjectType;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Default)]
|
||||
pub struct JsonSerializer;
|
||||
|
||||
impl<M: JsonModel> Serializer<M> for JsonSerializer {
|
||||
fn serialize(model: &M) -> SerializedModel {
|
||||
SerializedModel::new(serde_json::to_string(model).expect("model should serialize"))
|
||||
}
|
||||
|
||||
fn deserialize_owned(serialized: &str) -> anyhow::Result<M>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
Ok(serde_json::from_str(serialized)?)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user