feat(protocol): implement From<(usize, usize)> for SourceSpan

This commit is contained in:
Kat Marchán 2021-08-16 23:46:32 -07:00
parent f704d6a9ae
commit 36b86df9f5
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
2 changed files with 11 additions and 8 deletions

View File

@ -104,14 +104,8 @@ fn pretend_this_is_main() -> Result<(), MyBad> {
Err(MyBad { Err(MyBad {
src: Arc::new(src), src: Arc::new(src),
filename: "bad_file.rs".into(), filename: "bad_file.rs".into(),
snip: SourceSpan { snip: (0, (len - 1)).into(),
start: 0.into(), bad_bit: (9, 12).into(),
end: (len - 1).into(),
},
bad_bit: SourceSpan {
start: 9.into(),
end: 12.into(),
},
}) })
} }
``` ```

View File

@ -215,6 +215,15 @@ impl SourceSpan {
} }
} }
impl From<(ByteOffset, ByteOffset)> for SourceSpan {
fn from((start, end): (ByteOffset, ByteOffset)) -> Self {
Self {
start: start.into(),
end: end.into(),
}
}
}
/** /**
"Raw" type for the byte offset from the beginning of a [Source]. "Raw" type for the byte offset from the beginning of a [Source].
*/ */