mirror of
https://github.com/TxtDot/dalet.git
synced 2024-11-23 21:36:23 +03:00
fix(rust): create custom serializer
This commit is contained in:
parent
71db51b960
commit
306cc30791
3 changed files with 32 additions and 6 deletions
2
libs/rust/Cargo.lock
generated
2
libs/rust/Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "dalet"
|
||||
version = "1.0.0-pre0"
|
||||
version = "1.0.0-pre1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "dalet"
|
||||
version = "1.0.0-pre0"
|
||||
version = "1.0.0-pre1"
|
||||
edition = "2021"
|
||||
authors = ["artegoser"]
|
||||
license = "MIT"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct Tag {
|
||||
id: i8,
|
||||
body: Body,
|
||||
|
@ -13,16 +13,42 @@ impl Tag {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub enum Body {
|
||||
Text(String),
|
||||
Tag(Box<Tag>),
|
||||
Null,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
impl Serialize for Body {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
match *self {
|
||||
Body::Text(ref text) => serializer.serialize_str(text),
|
||||
Body::Tag(ref tag) => tag.serialize(serializer),
|
||||
Body::Null => serializer.serialize_str("null"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Argument {
|
||||
Text(String),
|
||||
Number(i8),
|
||||
Null,
|
||||
}
|
||||
|
||||
impl Serialize for Argument {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
match *self {
|
||||
Argument::Text(ref text) => serializer.serialize_str(text),
|
||||
Argument::Number(number) => serializer.serialize_i8(number),
|
||||
Argument::Null => serializer.serialize_str("null"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue