Skip to content

Commit c8ac04b

Browse files
committed
docs: Provide example for Level::no_name
1 parent 7059fd6 commit c8ac04b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/level.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,38 @@ impl<'a> Level<'a> {
7474
}
7575

7676
/// Do not show the [`Level`]s name
77+
///
78+
/// # Example
79+
///
80+
/// ```rust
81+
/// # use annotate_snippets::{Group, Snippet, AnnotationKind, Level};
82+
///let source = r#"fn main() {
83+
/// let b: &[u8] = include_str!("file.txt"); //~ ERROR mismatched types
84+
/// let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types
85+
/// }"#;
86+
/// let input = &[
87+
/// Group::with_title(Level::ERROR.title("mismatched types").id("E0308"))
88+
/// .element(
89+
/// Snippet::source(source)
90+
/// .path("$DIR/mismatched-types.rs")
91+
/// .annotation(
92+
/// AnnotationKind::Primary
93+
/// .span(105..131)
94+
/// .label("expected `&str`, found `&[u8; 0]`"),
95+
/// )
96+
/// .annotation(
97+
/// AnnotationKind::Context
98+
/// .span(98..102)
99+
/// .label("expected due to this"),
100+
/// ),
101+
/// )
102+
/// .element(
103+
/// Level::NOTE
104+
/// .no_name()
105+
/// .message("expected reference `&str`\nfound reference `&'static [u8; 0]`"),
106+
/// ),
107+
/// ];
108+
/// ```
77109
pub fn no_name(self) -> Level<'a> {
78110
self.with_name(None::<&str>)
79111
}

0 commit comments

Comments
 (0)