pub struct Group<'a> { /* private fields */ }Expand description
A Title with supporting context within a Report
Decor is used to visually connect Elements of a Group.
Generally, you will create separate group’s for:
- New Snippets, especially if they need their ownAnnotationKind::Primary
- Each logically distinct set of suggestions
§Example
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet};
use anstyle::AnsiColor;
use anstyle::Effects;
use anstyle::Style;
fn main() {
    let source = r#"// Make sure "highlighted" code is colored purple
//@ compile-flags: --error-format=human --color=always
//@ edition:2018
use core::pin::Pin;
use core::future::Future;
use core::any::Any;
fn query(_: fn(Box<(dyn Any + Send + '_)>) -> Pin<Box<(
    dyn Future<Output = Result<Box<(dyn Any + 'static)>, String>> + Send + 'static
)>>) {}
fn wrapped_fn<'a>(_: Box<(dyn Any + Send)>) -> Pin<Box<(
    dyn Future<Output = Result<Box<(dyn Any + 'static)>, String>> + Send + 'static
)>> {
    Box::pin(async { Err("nope".into()) })
}
fn main() {
    query(wrapped_fn);
}"#;
    const MAGENTA: Style = AnsiColor::Magenta.on_default().effects(Effects::BOLD);
    let message = format!(
        "expected fn pointer `{MAGENTA}for<'a>{MAGENTA:#} fn(Box<{MAGENTA}(dyn Any + Send + 'a){MAGENTA:#}>) -> Pin<_>`
      found fn item `fn(Box<{MAGENTA}(dyn Any + Send + 'static){MAGENTA:#}>) -> Pin<_> {MAGENTA}{{wrapped_fn}}{MAGENTA:#}`",
    );
    let report = &[
        Level::ERROR
            .primary_title("mismatched types")
            .id("E0308")
            .element(
                Snippet::source(source)
                    .path("$DIR/highlighting.rs")
                    .annotation(
                        AnnotationKind::Primary
                            .span(553..563)
                            .label("one type is more general than the other"),
                    )
                    .annotation(
                        AnnotationKind::Context
                            .span(547..552)
                            .label("arguments to this function are incorrect"),
                    ),
            )
            .element(Level::NOTE.message(&message)),
        Level::NOTE
            .secondary_title("function defined here")
            .element(
                Snippet::source(source)
                    .path("$DIR/highlighting.rs")
                    .annotation(AnnotationKind::Context.span(200..333).label(""))
                    .annotation(AnnotationKind::Primary.span(194..199)),
            ),
    ];
    let renderer = Renderer::styled()
        .anonymized_line_numbers(true)
        .decor_style(DecorStyle::Unicode);
    anstream::println!("{}", renderer.render(report));
}Implementations§
Source§impl<'a> Group<'a>
 
impl<'a> Group<'a>
Sourcepub fn with_title(title: Title<'a>) -> Self
 
pub fn with_title(title: Title<'a>) -> Self
Create group with a Title, deriving AnnotationKind::Primary from its Level
Sourcepub fn with_level(level: Level<'a>) -> Self
 
pub fn with_level(level: Level<'a>) -> Self
Create a title-less group with a primary Level for AnnotationKind::Primary
§Example
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Group, Level, Renderer, Snippet};
fn main() {
    let source = r#"# Docstring followed by a newline
def foobar(door, bar={}):
    """
    """
"#;
    let report = &[Group::with_level(Level::NOTE)
        .element(
            Snippet::source(source)
                .fold(false)
                .annotation(AnnotationKind::Primary.span(56..58).label("B006")),
        )
        .element(Level::HELP.message("Replace with `None`; initialize within function"))];
    let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
    anstream::println!("{}", renderer.render(report));
}Sourcepub fn elements(
    self,
    sections: impl IntoIterator<Item = impl Into<Element<'a>>>,
) -> Self
 
pub fn elements( self, sections: impl IntoIterator<Item = impl Into<Element<'a>>>, ) -> Self
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Group<'a>
impl<'a> RefUnwindSafe for Group<'a>
impl<'a> Send for Group<'a>
impl<'a> Sync for Group<'a>
impl<'a> Unpin for Group<'a>
impl<'a> UnwindSafe for Group<'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