After some discussion with PVH I realise that the repo structure in the last reorg was very rust-centric. In an attempt to put each language on a level footing move the rust code and project files into ./rust
24 lines
923 B
Rust
24 lines
923 B
Rust
use serde::{Serialize, Serializer};
|
|
|
|
use super::op::RawOpType;
|
|
use crate::{ObjType, OpType};
|
|
|
|
impl Serialize for OpType {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
// We convert to a `RawOpType` b/c here we only want to serialize the type of the `OpType`
|
|
// and not its associated data, since in JSON the associated data is under a different key.
|
|
let raw_type = match self {
|
|
OpType::Make(ObjType::Map) => RawOpType::MakeMap,
|
|
OpType::Make(ObjType::Table) => RawOpType::MakeTable,
|
|
OpType::Make(ObjType::List) => RawOpType::MakeList,
|
|
OpType::Make(ObjType::Text) => RawOpType::MakeText,
|
|
OpType::Delete => RawOpType::Del,
|
|
OpType::Increment(_) => RawOpType::Inc,
|
|
OpType::Put(_) => RawOpType::Set,
|
|
};
|
|
raw_type.serialize(serializer)
|
|
}
|
|
}
|