summaryrefslogtreecommitdiff
path: root/src/syntax/span.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-04-21 21:17:25 +0200
committerLaurenz <laurmaedje@gmail.com>2021-04-21 21:17:25 +0200
commit72478946c261f04754c11f8a6abf6eb0f43dea31 (patch)
treeb2a621804d39ace4e57ec4a51b34d40bb4a98987 /src/syntax/span.rs
parentdf58a4d89b67783b1ffc5c3b7282302d59db8c70 (diff)
Make frames serializable 📚
This also makes serialization support non-optional since it's too much feature-management for too little benefit.
Diffstat (limited to 'src/syntax/span.rs')
-rw-r--r--src/syntax/span.rs13
1 files changed, 6 insertions, 7 deletions
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<bool> = 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<T> {
/// The spanned value.
pub v: T,
@@ -53,8 +55,7 @@ impl<T: Debug> Debug for Spanned<T> {
}
/// 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,