Skip to content

Commit

Permalink
feat(offsets): more utility From impls for SourceSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 18, 2021
1 parent 53074d3 commit 9520036
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/protocol.rs
Expand Up @@ -252,6 +252,26 @@ impl<T: AsRef<str>> From<(T, ByteOffset, ByteOffset)> for SourceSpan {
}
}

impl From<(SourceOffset, SourceOffset)> for SourceSpan {
fn from((start, len): (SourceOffset, SourceOffset)) -> Self {
Self {
label: None,
offset: start,
length: len,
}
}
}

impl<T: AsRef<str>> From<(T, SourceOffset, SourceOffset)> for SourceSpan {
fn from((label, start, len): (T, SourceOffset, SourceOffset)) -> Self {
Self {
label: Some(label.as_ref().into()),
offset: start,
length: len,
}
}
}

/**
"Raw" type for the byte offset from the beginning of a [Source].
*/
Expand Down

0 comments on commit 9520036

Please sign in to comment.