From 81419f9636cfc99e09d1825569e045984434544c Mon Sep 17 00:00:00 2001 From: Serhiy Barhamon Date: Sat, 14 Oct 2023 11:29:15 +0200 Subject: [PATCH] serde serialize update enums are serialized to tags skip serialization of consumed_all_input field --- src/nodes/accordion.rs | 2 ++ src/nodes/accordion_tab.rs | 2 ++ src/nodes/bold.rs | 1 + src/nodes/cloudinary_image_gallery.rs | 1 + src/nodes/code.rs | 1 + src/nodes/divider.rs | 1 + src/nodes/embed.rs | 1 + src/nodes/heading.rs | 1 + src/nodes/highlight.rs | 2 ++ src/nodes/image.rs | 9 +++++---- src/nodes/image_gallery.rs | 2 ++ src/nodes/list.rs | 2 ++ src/nodes/list_item_content.rs | 2 ++ src/nodes/paragraph.rs | 2 ++ src/nodes/yamd.rs | 1 + 15 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/nodes/accordion.rs b/src/nodes/accordion.rs index 33ad7a9..09d760e 100644 --- a/src/nodes/accordion.rs +++ b/src/nodes/accordion.rs @@ -12,6 +12,7 @@ use crate::toolkit::{ use super::accordion_tab::AccordionTab; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum AccordionNodes { AccordionTab(AccordionTab), } @@ -40,6 +41,7 @@ impl From for AccordionNodes { #[derive(Debug, PartialEq, Serialize)] pub struct Accordion { + #[serde(skip_serializing)] consumed_all_input: bool, pub nodes: Vec, } diff --git a/src/nodes/accordion_tab.rs b/src/nodes/accordion_tab.rs index 467726d..9701920 100644 --- a/src/nodes/accordion_tab.rs +++ b/src/nodes/accordion_tab.rs @@ -16,6 +16,7 @@ use super::{ }; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum AccordionTabNodes { Pargaraph(Paragraph), Heading(Heading), @@ -127,6 +128,7 @@ impl From for AccordionTabNodes { pub struct AccordionTab { pub header: Option, pub nodes: Vec, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/bold.rs b/src/nodes/bold.rs index da916da..f3f33f1 100644 --- a/src/nodes/bold.rs +++ b/src/nodes/bold.rs @@ -15,6 +15,7 @@ use crate::{ }; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum BoldNodes { Text(Text), I(Italic), diff --git a/src/nodes/cloudinary_image_gallery.rs b/src/nodes/cloudinary_image_gallery.rs index 44d210c..bb000ee 100644 --- a/src/nodes/cloudinary_image_gallery.rs +++ b/src/nodes/cloudinary_image_gallery.rs @@ -8,6 +8,7 @@ use crate::toolkit::{context::Context, deserializer::Deserializer, matcher::Matc pub struct CloudinaryImageGallery { username: String, pub tag: String, + #[serde(skip_serializing)] pub consumed_all_input: bool, } diff --git a/src/nodes/code.rs b/src/nodes/code.rs index 84220fe..a207b1c 100644 --- a/src/nodes/code.rs +++ b/src/nodes/code.rs @@ -8,6 +8,7 @@ use crate::toolkit::{context::Context, deserializer::Deserializer, matcher::Matc pub struct Code { pub lang: String, pub code: String, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/divider.rs b/src/nodes/divider.rs index 3a9b93d..a458948 100644 --- a/src/nodes/divider.rs +++ b/src/nodes/divider.rs @@ -6,6 +6,7 @@ use crate::toolkit::{context::Context, deserializer::Deserializer, matcher::Matc #[derive(Debug, PartialEq, Serialize)] pub struct Divider { + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/embed.rs b/src/nodes/embed.rs index 6199bba..96449eb 100644 --- a/src/nodes/embed.rs +++ b/src/nodes/embed.rs @@ -8,6 +8,7 @@ use crate::toolkit::{deserializer::Deserializer, matcher::Matcher, node::Node}; pub struct Embed { pub url: String, pub kind: String, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/heading.rs b/src/nodes/heading.rs index e083d58..d00ee62 100644 --- a/src/nodes/heading.rs +++ b/src/nodes/heading.rs @@ -8,6 +8,7 @@ use crate::toolkit::{context::Context, deserializer::Deserializer, matcher::Matc pub struct Heading { pub level: u8, pub text: String, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/highlight.rs b/src/nodes/highlight.rs index d5889be..d432f97 100644 --- a/src/nodes/highlight.rs +++ b/src/nodes/highlight.rs @@ -12,6 +12,7 @@ use crate::toolkit::{ use super::paragraph::Paragraph; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum HighlightNodes { Paragraph(Paragraph), } @@ -43,6 +44,7 @@ pub struct Highlight { pub header: Option, pub icon: Option, pub nodes: Vec, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/image.rs b/src/nodes/image.rs index f13e1ea..58f3101 100644 --- a/src/nodes/image.rs +++ b/src/nodes/image.rs @@ -7,7 +7,8 @@ use crate::toolkit::{context::Context, deserializer::Deserializer, matcher::Matc #[derive(Debug, PartialEq, Serialize)] pub struct Image { pub alt: String, - pub url: String, + pub src: String, + #[serde(skip_serializing)] consumed_all_input: bool, } @@ -15,7 +16,7 @@ impl Image { pub fn new>(consumed_all_input: bool, alt: S, url: S) -> Self { Self { alt: alt.into(), - url: url.into(), + src: url.into(), consumed_all_input, } } @@ -29,14 +30,14 @@ impl Display for Image { "\n\n" }; - write!(f, "![{}]({}){}", self.alt, self.url, end) + write!(f, "![{}]({}){}", self.alt, self.src, end) } } impl Node for Image { fn len(&self) -> usize { let end = if self.consumed_all_input { 1 } else { 2 }; - self.alt.len() + self.url.len() + 5 + end + self.alt.len() + self.src.len() + 5 + end } } diff --git a/src/nodes/image_gallery.rs b/src/nodes/image_gallery.rs index 7e18222..adfad36 100644 --- a/src/nodes/image_gallery.rs +++ b/src/nodes/image_gallery.rs @@ -12,6 +12,7 @@ use crate::toolkit::{ use super::image::Image; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum ImageGalleryNodes { Image(Image), } @@ -43,6 +44,7 @@ impl From for ImageGalleryNodes { #[derive(Debug, PartialEq, Serialize)] pub struct ImageGallery { pub nodes: Vec, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/list.rs b/src/nodes/list.rs index 1b56a14..19415a8 100644 --- a/src/nodes/list.rs +++ b/src/nodes/list.rs @@ -18,6 +18,7 @@ pub enum ListTypes { } #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum ListNodes { ListItem(ListItem), } @@ -49,6 +50,7 @@ pub struct List { pub list_type: ListTypes, pub level: usize, pub nodes: Vec, + #[serde(skip_serializing)] consumed_all_input: bool, } diff --git a/src/nodes/list_item_content.rs b/src/nodes/list_item_content.rs index 3b10af7..10b1106 100644 --- a/src/nodes/list_item_content.rs +++ b/src/nodes/list_item_content.rs @@ -15,6 +15,7 @@ use super::{ }; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum ListItemContentNodes { A(Anchor), B(Bold), @@ -88,6 +89,7 @@ impl Node for ListItemContentNodes { #[derive(Debug, PartialEq, Serialize)] pub struct ListItemContent { + #[serde(skip_serializing)] consumed_all_input: bool, pub nodes: Vec, } diff --git a/src/nodes/paragraph.rs b/src/nodes/paragraph.rs index 0ccc406..49601cf 100644 --- a/src/nodes/paragraph.rs +++ b/src/nodes/paragraph.rs @@ -14,6 +14,7 @@ use crate::toolkit::{ }; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum ParagraphNodes { A(Anchor), B(Bold), @@ -87,6 +88,7 @@ impl Node for ParagraphNodes { #[derive(Debug, PartialEq, Serialize)] pub struct Paragraph { + #[serde(skip_serializing)] consumed_all_input: bool, pub nodes: Vec, } diff --git a/src/nodes/yamd.rs b/src/nodes/yamd.rs index cadc36b..d279698 100644 --- a/src/nodes/yamd.rs +++ b/src/nodes/yamd.rs @@ -16,6 +16,7 @@ use super::{ }; #[derive(Debug, PartialEq, Serialize)] +#[serde(tag = "type")] pub enum YamdNodes { P(Paragraph), H(Heading),