Skip to content

Commit

Permalink
Relax lifetime constraints in language::embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
SandaruKasa committed Jan 14, 2025
1 parent edbd5d5 commit 964e18b
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/language/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,37 @@ pub(crate) struct SimpleCapture<'a> {
}

impl<'a> HtmlLike<'a> {
pub fn start_script_in_range(
&'a self,
pub fn start_script_in_range<'this>(
&'this self,
start: usize,
end: usize,
) -> Option<impl Iterator<Item = &'a Capture<'a>>> {
) -> Option<impl Iterator<Item = &'this Capture<'a>>> {
filter_range(self.start_script.as_ref()?, start, end)
}

pub fn start_style_in_range(
&'a self,
pub fn start_style_in_range<'this>(
&'this self,
start: usize,
end: usize,
) -> Option<impl Iterator<Item = &'a Capture<'a>>> {
) -> Option<impl Iterator<Item = &'this Capture<'a>>> {
filter_range(self.start_style.as_ref()?, start, end)
}

pub fn start_template_in_range(
&'a self,
pub fn start_template_in_range<'this>(
&'this self,
start: usize,
end: usize,
) -> Option<impl Iterator<Item = &'a Capture<'a>>> {
) -> Option<impl Iterator<Item = &'this Capture<'a>>> {
filter_range(self.start_template.as_ref()?, start, end)
}
}

impl<'a> SimpleCapture<'a> {
pub fn starts_in_range(&'a self, start: usize, end: usize) -> Option<&Capture<'a>> {
pub fn starts_in_range<'this>(
&'this self,
start: usize,
end: usize,
) -> Option<&'this Capture<'a>> {
filter_range(self.starts.as_ref()?, start, end).and_then(|mut it| it.next())
}

Expand All @@ -128,11 +132,11 @@ impl<'a> SimpleCapture<'a> {
}
}

fn filter_range<'a>(
dataset: &'a [Capture<'a>],
fn filter_range<'dataset, 'cap>(
dataset: &'dataset [Capture<'cap>],
start: usize,
end: usize,
) -> Option<impl Iterator<Item = &'a Capture<'a>>> {
) -> Option<impl Iterator<Item = &'dataset Capture<'cap>>> {
let pos = dataset
.binary_search_by_key(&start, |cap| cap.start())
.ok()?;
Expand Down

0 comments on commit 964e18b

Please sign in to comment.