Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e60193

Browse files
committed
chore(renderer): Add doc comments
1 parent d87d015 commit 7e60193

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

‎src/renderer/mod.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
//! The renderer for [`Snippet`]s
2+
//!
3+
//! # Example
4+
//! ```
5+
//! use annotate_snippets::renderer::Renderer;
6+
//! use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet};
7+
//! let snippet = Snippet {
8+
//! title: Some(Annotation {
9+
//! label: Some("mismatched types"),
10+
//! id: None,
11+
//! annotation_type: AnnotationType::Error,
12+
//! }),
13+
//! footer: vec![],
14+
//! slices: vec![
15+
//! Slice {
16+
//! source: "Foo",
17+
//! line_start: 51,
18+
//! origin: Some("src/format.rs"),
19+
//! fold: false,
20+
//! annotations: vec![],
21+
//! },
22+
//! Slice {
23+
//! source: "Faa",
24+
//! line_start: 129,
25+
//! origin: Some("src/display.rs"),
26+
//! fold: false,
27+
//! annotations: vec![],
28+
//! },
29+
//! ],
30+
//! };
31+
//!
32+
//! let renderer = Renderer::styled();
33+
//! println!("{}", renderer.render(snippet));
34+
135
pub mod margin;
236

337
use crate::display_list::DisplayList;
@@ -6,6 +40,7 @@ use anstyle::{AnsiColor, Effects, Style};
640
use margin::Margin;
741
use std::fmt::Display;
842

43+
/// A renderer for [`Snippet`]s
944
#[derive(Clone)]
1045
pub struct Renderer {
1146
anonymized_line_numbers: bool,
@@ -14,6 +49,7 @@ pub struct Renderer {
1449
}
1550

1651
impl Renderer {
52+
/// Render a snippet into a `Display`able object
1753
pub fn render<'a>(&'a self, snippet: Snippet<'a>) -> impl Display + 'a {
1854
DisplayList::new(
1955
snippet,
@@ -50,51 +86,90 @@ impl Renderer {
5086
}
5187
}
5288

89+
/// Anonymize line numbers
90+
///
91+
/// This enables (or disables) line number anonymization. When enabled, line numbers are replaced
92+
/// with `LL`.
93+
///
94+
/// # Example
95+
///
96+
/// ```text
97+
/// --> $DIR/whitespace-trimming.rs:4:193
98+
/// |
99+
/// LL | ... let _: () = 42;
100+
/// | ^^ expected (), found integer
101+
/// |
102+
/// ```
53103
pub const fn anonymized_line_numbers(mut self, anonymized_line_numbers: bool) -> Self {
54104
self.anonymized_line_numbers = anonymized_line_numbers;
55105
self
56106
}
57107

108+
/// Set the margin for the output
109+
///
110+
/// This controls the various margins of the output.
111+
///
112+
/// # Example
113+
///
114+
/// ```text
115+
/// error: expected type, found `22`
116+
/// --> examples/footer.rs:29:25
117+
/// |
118+
/// 26 | ... annotations: vec![SourceAnnotation {
119+
/// | ---------------- info: while parsing this struct
120+
/// ...
121+
/// 29 | ... range: <22, 25>,
122+
/// | ^^
123+
/// |
124+
/// ```
58125
pub const fn margin(mut self, margin: Option<Margin>) -> Self {
59126
self.margin = margin;
60127
self
61128
}
62129

130+
/// Set the output style for `error`
63131
pub const fn error(mut self, style: Style) -> Self {
64132
self.stylesheet.error = style;
65133
self
66134
}
67135

136+
/// Set the output style for `warning`
68137
pub const fn warning(mut self, style: Style) -> Self {
69138
self.stylesheet.warning = style;
70139
self
71140
}
72141

142+
/// Set the output style for `info`
73143
pub const fn info(mut self, style: Style) -> Self {
74144
self.stylesheet.info = style;
75145
self
76146
}
77147

148+
/// Set the output style for `note`
78149
pub const fn note(mut self, style: Style) -> Self {
79150
self.stylesheet.note = style;
80151
self
81152
}
82153

154+
/// Set the output style for `help`
83155
pub const fn help(mut self, style: Style) -> Self {
84156
self.stylesheet.help = style;
85157
self
86158
}
87159

160+
/// Set the output style for line numbers
88161
pub const fn line_no(mut self, style: Style) -> Self {
89162
self.stylesheet.line_no = style;
90163
self
91164
}
92165

166+
/// Set the output style for emphasis
93167
pub const fn emphasis(mut self, style: Style) -> Self {
94168
self.stylesheet.emphasis = style;
95169
self
96170
}
97171

172+
/// Set the output style for none
98173
pub const fn none(mut self, style: Style) -> Self {
99174
self.stylesheet.none = style;
100175
self

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /