pub struct Annotation<'a> { /* private fields */ }
Expand description
Highlight and describe a span of text within a Snippet
See AnnotationKind
to create an annotation.
§Example
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
fn main() {
let source = r#" annotations: vec![SourceAnnotation {
label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
,
range: <22, 25>,"#;
let report =
&[
Group::with_title(Level::ERROR.primary_title("expected type, found `22`")).element(
Snippet::source(source)
.line_start(26)
.path("examples/footer.rs")
.annotation(AnnotationKind::Primary.span(193..195).label(
"expected struct `annotate_snippets::snippet::Slice`, found reference",
))
.annotation(
AnnotationKind::Context
.span(34..50)
.label("while parsing this struct"),
),
),
];
let renderer = Renderer::styled();
anstream::println!("{}", renderer.render(report));
}
Implementations§
Source§impl<'a> Annotation<'a>
impl<'a> Annotation<'a>
Sourcepub fn label(self, label: impl Into<OptionCow<'a>>) -> Self
pub fn label(self, label: impl Into<OptionCow<'a>>) -> Self
Describe the reason the span is highlighted
This will be styled according to the AnnotationKind
Text passed to this function is considered “untrusted input”, as such all text is passed through a normalization function. Pre-styled text is not allowed to be passed to this function.
Sourcepub fn highlight_source(self, highlight_source: bool) -> Self
pub fn highlight_source(self, highlight_source: bool) -> Self
Style the source according to the AnnotationKind
This gives extra emphasis to this annotation
Trait Implementations§
Source§impl<'a> Clone for Annotation<'a>
impl<'a> Clone for Annotation<'a>
Source§fn clone(&self) -> Annotation<'a>
fn clone(&self) -> Annotation<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<'a> Freeze for Annotation<'a>
impl<'a> RefUnwindSafe for Annotation<'a>
impl<'a> Send for Annotation<'a>
impl<'a> Sync for Annotation<'a>
impl<'a> Unpin for Annotation<'a>
impl<'a> UnwindSafe for Annotation<'a>
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