feat(source): derive common traits for NamedSource, SourceSpan, and SourceOffset (#340)

This commit is contained in:
Brooks Rady 2024-02-08 22:16:49 +00:00 committed by GitHub
parent c2f06f6cca
commit 6f09250cca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@ use crate::{MietteError, MietteSpanContents, SourceCode, SpanContents};
/// Utility struct for when you have a regular [`SourceCode`] type that doesn't /// 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 /// implement `name`. For example [`String`]. Or if you want to override the
/// `name` returned by the `SourceCode`. /// `name` returned by the `SourceCode`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NamedSource<S: SourceCode + 'static> { pub struct NamedSource<S: SourceCode + 'static> {
source: S, source: S,
name: String, name: String,

View File

@ -550,7 +550,7 @@ impl<'a> SpanContents<'a> for MietteSpanContents<'a> {
} }
/// Span within a [`SourceCode`] /// 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))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SourceSpan { pub struct SourceSpan {
/// The start of the span. /// The start of the span.
@ -652,7 +652,7 @@ pub type ByteOffset = usize;
/** /**
Newtype that represents the [`ByteOffset`] from the beginning of a [`SourceCode`] 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))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SourceOffset(ByteOffset); pub struct SourceOffset(ByteOffset);