Skip to content

Commit

Permalink
feat(protocol): implement From<(usize, usize)> for SourceSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 17, 2021
1 parent f704d6a commit 36b86df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,8 @@ fn pretend_this_is_main() -> Result<(), MyBad> {
Err(MyBad {
src: Arc::new(src),
filename: "bad_file.rs".into(),
snip: SourceSpan {
start: 0.into(),
end: (len - 1).into(),
},
bad_bit: SourceSpan {
start: 9.into(),
end: 12.into(),
},
snip: (0, (len - 1)).into(),
bad_bit: (9, 12).into(),
})
}
```
Expand Down
9 changes: 9 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
*/
Expand Down

0 comments on commit 36b86df

Please sign in to comment.