From 6f09250cca14561f07fba899a8e6d3c0df14230e Mon Sep 17 00:00:00 2001 From: Brooks Rady Date: Thu, 8 Feb 2024 22:16:49 +0000 Subject: [PATCH] feat(source): derive common traits for NamedSource, SourceSpan, and SourceOffset (#340) --- src/named_source.rs | 1 + src/protocol.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/named_source.rs b/src/named_source.rs index 99e74a8c..ea11cd2c 100644 --- a/src/named_source.rs +++ b/src/named_source.rs @@ -3,6 +3,7 @@ use crate::{MietteError, MietteSpanContents, SourceCode, SpanContents}; /// Utility struct for when you have a regular [`SourceCode`] type that doesn't /// implement `name`. For example [`String`]. Or if you want to override the /// `name` returned by the `SourceCode`. +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct NamedSource { source: S, name: String, diff --git a/src/protocol.rs b/src/protocol.rs index 310fc869..9f312db8 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -550,7 +550,7 @@ impl<'a> SpanContents<'a> for MietteSpanContents<'a> { } /// Span within a [`SourceCode`] -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SourceSpan { /// The start of the span. @@ -652,7 +652,7 @@ pub type ByteOffset = usize; /** Newtype that represents the [`ByteOffset`] from the beginning of a [`SourceCode`] */ -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct SourceOffset(ByteOffset);