Add serde support
This commit is contained in:
parent
8239b2b51d
commit
b7c31f6895
16 changed files with 32 additions and 148 deletions
|
@ -1,4 +1,5 @@
|
|||
use databake::Bake;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::CowStr;
|
||||
use std::{borrow::Cow, fmt};
|
||||
|
@ -35,7 +36,7 @@ pub fn valid(src: &str) -> usize {
|
|||
|
||||
/// Stores an attribute value that supports backslash escapes of ASCII punctuation upon displaying,
|
||||
/// without allocating.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Bake)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub struct AttributeValue<'s> {
|
||||
raw: CowStr<'s>,
|
||||
|
@ -123,9 +124,9 @@ impl<'s> Iterator for AttributeValueParts<'s> {
|
|||
// Attributes are relatively rare, we choose to pay 8 bytes always and sometimes an extra
|
||||
// indirection instead of always 24 bytes.
|
||||
#[allow(clippy::box_vec)]
|
||||
#[derive(Clone, PartialEq, Eq, Default, Bake)]
|
||||
#[derive(Clone, PartialEq, Eq, Default, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub struct Attributes<'s>(pub Option<Cow<'s, [(&'s str, AttributeValue<'s>)]>>);
|
||||
pub struct Attributes<'s>(#[serde(borrow)] pub Option<Cow<'s, [(&'s str, AttributeValue<'s>)]>>);
|
||||
|
||||
impl<'s> Attributes<'s> {
|
||||
/// Create an empty collection.
|
||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -68,6 +68,7 @@ mod lex;
|
|||
|
||||
pub use attr::{AttributeValue, AttributeValueParts, Attributes};
|
||||
use databake::Bake;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
type CowStr<'s> = std::borrow::Cow<'s, str>;
|
||||
|
||||
|
@ -203,7 +204,7 @@ impl<'s> AsRef<Event<'s>> for &Event<'s> {
|
|||
/// multiple events. [`Container`] elements are represented by a [`Event::Start`] followed by
|
||||
/// events representing its content, and finally a [`Event::End`]. Atomic elements without any
|
||||
/// inside elements are represented by a single event.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum Event<'s> {
|
||||
/// Start of a container.
|
||||
|
@ -251,7 +252,7 @@ pub enum Event<'s> {
|
|||
/// - inline, may only contain inline elements,
|
||||
/// - block leaf, may only contain inline elements,
|
||||
/// - block container, may contain any block-level elements.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum Container<'s> {
|
||||
/// A blockquote element.
|
||||
|
@ -406,7 +407,7 @@ impl<'s> Container<'s> {
|
|||
}
|
||||
|
||||
/// Alignment of a table column.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum Alignment {
|
||||
Unspecified,
|
||||
|
@ -416,7 +417,7 @@ pub enum Alignment {
|
|||
}
|
||||
|
||||
/// The type of an inline span link.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum SpanLinkType {
|
||||
/// E.g. `[text](url)`
|
||||
|
@ -428,7 +429,7 @@ pub enum SpanLinkType {
|
|||
}
|
||||
|
||||
/// The type of an inline link.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum LinkType {
|
||||
/// E.g. `[text](url)`.
|
||||
|
@ -440,7 +441,7 @@ pub enum LinkType {
|
|||
}
|
||||
|
||||
/// The type of a list.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum ListKind {
|
||||
/// A bullet list.
|
||||
|
@ -456,7 +457,7 @@ pub enum ListKind {
|
|||
}
|
||||
|
||||
/// Numbering type of an ordered list.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum OrderedListNumbering {
|
||||
/// Decimal numbering, e.g. `1)`.
|
||||
|
@ -472,7 +473,7 @@ pub enum OrderedListNumbering {
|
|||
}
|
||||
|
||||
/// Style of an ordered list.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Bake, Deserialize, Serialize)]
|
||||
#[databake(path = jotdown)]
|
||||
pub enum OrderedListStyle {
|
||||
/// Number is followed by a period, e.g. `1.`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue