pub struct SpanContext { /* private fields */ }Expand description
A runtime error context carrying the source span of the failing operation.
Add this as anyhow context with .context(SpanContext::new(span)) when wrapping
an op closure. Retrieve it from an anyhow::Error with e.downcast_ref::<SpanContext>().
Implementations§
Source§impl SpanContext
impl SpanContext
Sourcepub fn new(span: SourceSpan) -> Self
pub fn new(span: SourceSpan) -> Self
Creates a new span context for the given source region.
§Examples
use cel_parser::{SourceSpan, SpanContext};
let span = SourceSpan::new(1, 0, 1, 5);
let ctx = SpanContext::new(span);
assert_eq!(ctx.span(), span);Sourcepub fn span(&self) -> SourceSpan
pub fn span(&self) -> SourceSpan
Returns the source span.
§Examples
use cel_parser::{SourceSpan, SpanContext};
let span = SourceSpan::new(2, 3, 2, 7);
let ctx = SpanContext::new(span);
assert_eq!(ctx.span(), span);Sourcepub fn format_rustc_style(
&self,
message: &str,
source_code: &str,
filename: &str,
start_line: u32,
renderer: &Renderer,
) -> String
pub fn format_rustc_style( &self, message: &str, source_code: &str, filename: &str, start_line: u32, renderer: &Renderer, ) -> String
Formats a runtime error message with rustc-style source annotation.
Delegates to CELError::format_rustc_style using self.span and message.
§Examples
use annotate_snippets::Renderer;
use cel_parser::{SourceSpan, SpanContext};
let source = "1i32 + 2i32";
let span = SourceSpan::new(1, 5, 1, 6);
let ctx = SpanContext::new(span);
let output = ctx.format_rustc_style("arithmetic overflow", source, "test.cel", 1, &Renderer::plain());
assert!(output.contains("arithmetic overflow"));Trait Implementations§
Source§impl Debug for SpanContext
impl Debug for SpanContext
Source§impl Display for SpanContext
impl Display for SpanContext
Source§impl Error for SpanContext
impl Error for SpanContext
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for SpanContext
impl RefUnwindSafe for SpanContext
impl Send for SpanContext
impl Sync for SpanContext
impl Unpin for SpanContext
impl UnsafeUnpin for SpanContext
impl UnwindSafe for SpanContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more