Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax lifetime constraints in language::embedding #1225

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading