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

add methods on the error types for reusability in wgsl-analyzer #1827

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,16 @@ pub struct ParseError {
}

impl ParseError {
pub fn labels(&self) -> impl Iterator<Item = (Span, &str)> + ExactSizeIterator + '_ {
self.labels
.iter()
.map(|&(ref span, ref msg)| (span.clone(), msg.as_ref()))
}

pub fn message(&self) -> &str {
&self.message
}

fn diagnostic(&self) -> Diagnostic<()> {
let diagnostic = Diagnostic::error()
.with_message(self.message.to_string())
Expand Down
6 changes: 5 additions & 1 deletion src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ impl<E> WithSpan<E> {
self.inner
}

pub fn as_inner(&self) -> &E {
&self.inner
}

/// Iterator over stored [`SpanContext`]s.
pub fn spans(&self) -> impl Iterator<Item = &SpanContext> {
pub fn spans(&self) -> impl Iterator<Item = &SpanContext> + ExactSizeIterator {
#[cfg(feature = "span")]
return self.spans.iter();
#[cfg(not(feature = "span"))]
Expand Down