Implement From<Located> for Range (#3377)

This commit is contained in:
Charlie Marsh 2023-03-08 13:50:20 -05:00 committed by GitHub
parent ff2c0dd491
commit 130e733023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
232 changed files with 612 additions and 719 deletions

View file

@ -125,8 +125,9 @@ impl<'a> Locator<'a> {
}
/// Take the source code between the given [`Range`].
pub fn slice(&self, range: Range) -> &'a str {
pub fn slice<R: Into<Range>>(&self, range: R) -> &'a str {
let index = self.get_or_init_index();
let range = range.into();
let start = truncate(range.location, index, self.contents);
let end = truncate(range.end_location, index, self.contents);
&self.contents[start..end]