feat(offsets): more utility From impls for SourceSpan

This commit is contained in:
Kat Marchán 2021-08-17 18:30:38 -07:00
parent 53074d3488
commit 95200366a1
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 20 additions and 0 deletions

View File

@ -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].
*/