Skip to content

Commit

Permalink
Merge pull request #29 from Lurk/serde_deserialize_update
Browse files Browse the repository at this point in the history
serde serialize update
  • Loading branch information
Lurk authored Oct 14, 2023
2 parents 1d0f329 + 81419f9 commit 118828b
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/nodes/accordion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::toolkit::{
use super::accordion_tab::AccordionTab;

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum AccordionNodes {
AccordionTab(AccordionTab),
}
Expand Down Expand Up @@ -40,6 +41,7 @@ impl From<AccordionTab> for AccordionNodes {

#[derive(Debug, PartialEq, Serialize)]
pub struct Accordion {
#[serde(skip_serializing)]
consumed_all_input: bool,
pub nodes: Vec<AccordionNodes>,
}
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/accordion_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use super::{
};

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum AccordionTabNodes {
Pargaraph(Paragraph),
Heading(Heading),
Expand Down Expand Up @@ -127,6 +128,7 @@ impl From<Code> for AccordionTabNodes {
pub struct AccordionTab {
pub header: Option<String>,
pub nodes: Vec<AccordionTabNodes>,
#[serde(skip_serializing)]
consumed_all_input: bool,
}

Expand Down
1 change: 1 addition & 0 deletions src/nodes/bold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
};

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum BoldNodes {
Text(Text),
I(Italic),
Expand Down
1 change: 1 addition & 0 deletions src/nodes/cloudinary_image_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions src/nodes/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions src/nodes/divider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions src/nodes/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
1 change: 1 addition & 0 deletions src/nodes/heading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 2 additions & 0 deletions src/nodes/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::toolkit::{
use super::paragraph::Paragraph;

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum HighlightNodes {
Paragraph(Paragraph),
}
Expand Down Expand Up @@ -43,6 +44,7 @@ pub struct Highlight {
pub header: Option<String>,
pub icon: Option<String>,
pub nodes: Vec<HighlightNodes>,
#[serde(skip_serializing)]
consumed_all_input: bool,
}

Expand Down
9 changes: 5 additions & 4 deletions src/nodes/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ 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,
}

impl Image {
pub fn new<S: Into<String>>(consumed_all_input: bool, alt: S, url: S) -> Self {
Self {
alt: alt.into(),
url: url.into(),
src: url.into(),
consumed_all_input,
}
}
Expand All @@ -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
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/nodes/image_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::toolkit::{
use super::image::Image;

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum ImageGalleryNodes {
Image(Image),
}
Expand Down Expand Up @@ -43,6 +44,7 @@ impl From<Image> for ImageGalleryNodes {
#[derive(Debug, PartialEq, Serialize)]
pub struct ImageGallery {
pub nodes: Vec<ImageGalleryNodes>,
#[serde(skip_serializing)]
consumed_all_input: bool,
}

Expand Down
2 changes: 2 additions & 0 deletions src/nodes/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum ListTypes {
}

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum ListNodes {
ListItem(ListItem),
}
Expand Down Expand Up @@ -49,6 +50,7 @@ pub struct List {
pub list_type: ListTypes,
pub level: usize,
pub nodes: Vec<ListNodes>,
#[serde(skip_serializing)]
consumed_all_input: bool,
}

Expand Down
2 changes: 2 additions & 0 deletions src/nodes/list_item_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::{
};

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum ListItemContentNodes {
A(Anchor),
B(Bold),
Expand Down Expand Up @@ -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<ListItemContentNodes>,
}
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::toolkit::{
};

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum ParagraphNodes {
A(Anchor),
B(Bold),
Expand Down Expand Up @@ -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<ParagraphNodes>,
}
Expand Down
1 change: 1 addition & 0 deletions src/nodes/yamd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use super::{
};

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type")]
pub enum YamdNodes {
P(Paragraph),
H(Heading),
Expand Down

0 comments on commit 118828b

Please sign in to comment.