summaryrefslogtreecommitdiff
path: root/src/syntax/span.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-09-30 14:38:46 +0200
committerLaurenz <laurmaedje@gmail.com>2020-09-30 14:38:46 +0200
commit3c3730425f0a9a4241c4f57cb7f4d00b71db201e (patch)
tree8e63405574bc3909dddc2d3e8402a66bb2a8f059 /src/syntax/span.rs
parent7143e10afccc7beef22646f6c7355075f97afb2c (diff)
SpanWith trait ↔
Diffstat (limited to 'src/syntax/span.rs')
-rw-r--r--src/syntax/span.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/syntax/span.rs b/src/syntax/span.rs
index 6f5420d4..cda35ec0 100644
--- a/src/syntax/span.rs
+++ b/src/syntax/span.rs
@@ -17,6 +17,16 @@ pub trait Offset {
fn offset(self, by: Pos) -> Self;
}
+/// Annotate a value with a span.
+pub trait SpanWith: Sized {
+ /// Wraps `self` in a `Spanned` with the given span.
+ fn span_with(self, span: Span) -> Spanned<Self> {
+ Spanned::new(self, span)
+ }
+}
+
+impl<T> SpanWith for T {}
+
/// A vector of spanned values of type `T`.
pub type SpanVec<T> = Vec<Spanned<T>>;