From 72478946c261f04754c11f8a6abf6eb0f43dea31 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 21 Apr 2021 21:17:25 +0200 Subject: =?UTF-8?q?Make=20frames=20serializable=20=F0=9F=93=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also makes serialization support non-optional since it's too much feature-management for too little benefit. --- src/syntax/node.rs | 14 +++++++------- src/syntax/span.rs | 13 ++++++------- 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/node.rs b/src/syntax/node.rs index 537a5686..5f76b56a 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -37,15 +37,15 @@ impl Node { /// Desugar markup into a function call. pub fn desugar(&self) -> Option { match *self { - Node::Text(_) => None, - Node::Space => None, - Node::Linebreak(span) => Some(call(span, Self::LINEBREAK)), - Node::Parbreak(span) => Some(call(span, Self::PARBREAK)), - Node::Strong(span) => Some(call(span, Self::STRONG)), - Node::Emph(span) => Some(call(span, Self::EMPH)), + Self::Text(_) => None, + Self::Space => None, + Self::Linebreak(span) => Some(call(span, Self::LINEBREAK)), + Self::Parbreak(span) => Some(call(span, Self::PARBREAK)), + Self::Strong(span) => Some(call(span, Self::STRONG)), + Self::Emph(span) => Some(call(span, Self::EMPH)), Self::Heading(ref heading) => Some(heading.desugar()), Self::Raw(ref raw) => Some(raw.desugar()), - Node::Expr(_) => None, + Self::Expr(_) => None, } } } diff --git a/src/syntax/span.rs b/src/syntax/span.rs index d3683c1a..f9b1d312 100644 --- a/src/syntax/span.rs +++ b/src/syntax/span.rs @@ -2,13 +2,15 @@ use std::cell::Cell; use std::fmt::{self, Debug, Display, Formatter}; use std::ops::{Add, Range}; +use serde::{Deserialize, Serialize}; + thread_local! { static CMP_SPANS: Cell = Cell::new(true); } /// A value with the span it corresponds to in the source code. #[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Serialize, Deserialize)] pub struct Spanned { /// The spanned value. pub v: T, @@ -53,8 +55,7 @@ impl Debug for Spanned { } /// Bounds of a slice of source code. -#[derive(Copy, Clone, Ord, PartialOrd)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Copy, Clone, Ord, PartialOrd, Serialize, Deserialize)] pub struct Span { /// The inclusive start position. pub start: Pos, @@ -158,8 +159,7 @@ impl Debug for Span { } /// A byte position in source code. -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] pub struct Pos(pub u32); impl Pos { @@ -208,8 +208,7 @@ impl Debug for Pos { } /// A one-indexed line-column position in source code. -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] pub struct Location { /// The one-indexed line. pub line: u32, -- cgit v1.2.3