pub struct Emitter<'a, T: FileData> { /* private fields */ }
Expand description
Formats and prints diagnostic messages.
Implementations§
Source§impl<'a, T: FileData> Emitter<'a, T>
impl<'a, T: FileData> Emitter<'a, T>
Sourcepub fn stderr(
color_config: ColorConfig,
code_map: Option<&'a CodeMap<T>>,
) -> Self
pub fn stderr( color_config: ColorConfig, code_map: Option<&'a CodeMap<T>>, ) -> Self
Creates an emitter wrapping stderr.
Examples found in repository?
examples/simple.rs (line 31)
7fn main() {
8 let file = r#"
9pub fn look_up_pos(&self, pos: Pos) -> Loc {
10 let file = self.find_file(pos);
11 let position = file.find_line_col(pos);
12 Loc { file, position }
13}
14"#;
15
16 let mut codemap = CodeMap::new();
17 let file_span = codemap.add_file(DefaultFileData::new("test.rs".to_owned(), file.to_owned())).span;
18 let fn_span = file_span.subspan(8, 19);
19 let ret_span = file_span.subspan(40, 43);
20 let var_span = file_span.subspan(54, 58);
21
22 let sl = SpanLabel { span: fn_span, style: SpanStyle::Primary, label:Some("function name".to_owned()) };
23 let sl2 = SpanLabel { span: ret_span, style: SpanStyle::Primary, label:Some("returns".to_owned()) };
24 let d1 = Diagnostic { level:Level::Error, message:"Test error".to_owned(), code:Some("C000".to_owned()), spans: vec![sl, sl2] };
25
26 let sl3 = SpanLabel { span: var_span, style: SpanStyle::Primary, label:Some("variable".to_owned()) };
27 let d2 = Diagnostic { level:Level::Warning, message:"Test warning".to_owned(), code:Some("W000".to_owned()), spans: vec![sl3] };
28
29 let d3 = Diagnostic { level: Level::Help, message:"Help message".to_owned(), code: None, spans: vec![] };
30
31 let mut emitter = Emitter::stderr(ColorConfig::Auto, Some(&codemap));
32 emitter.emit(&[d1, d2, d3]);
33}
Sourcepub fn vec(vec: &'a mut Vec<u8>, code_map: Option<&'a CodeMap<T>>) -> Self
pub fn vec(vec: &'a mut Vec<u8>, code_map: Option<&'a CodeMap<T>>) -> Self
Creates an emitter wrapping a vector.
Sourcepub fn new(
dst: Box<dyn Write + Send + 'a>,
code_map: Option<&'a CodeMap<T>>,
) -> Self
pub fn new( dst: Box<dyn Write + Send + 'a>, code_map: Option<&'a CodeMap<T>>, ) -> Self
Creates an emitter wrapping a boxed Write
trait object.
Sourcepub fn emit(&mut self, msgs: &[Diagnostic])
pub fn emit(&mut self, msgs: &[Diagnostic])
Print a group of diagnostic messages.
The messages within a group are printed atomically without spacing between them, and share consistent formatting elements, such as aligned line number width.
Examples found in repository?
examples/simple.rs (line 32)
7fn main() {
8 let file = r#"
9pub fn look_up_pos(&self, pos: Pos) -> Loc {
10 let file = self.find_file(pos);
11 let position = file.find_line_col(pos);
12 Loc { file, position }
13}
14"#;
15
16 let mut codemap = CodeMap::new();
17 let file_span = codemap.add_file(DefaultFileData::new("test.rs".to_owned(), file.to_owned())).span;
18 let fn_span = file_span.subspan(8, 19);
19 let ret_span = file_span.subspan(40, 43);
20 let var_span = file_span.subspan(54, 58);
21
22 let sl = SpanLabel { span: fn_span, style: SpanStyle::Primary, label:Some("function name".to_owned()) };
23 let sl2 = SpanLabel { span: ret_span, style: SpanStyle::Primary, label:Some("returns".to_owned()) };
24 let d1 = Diagnostic { level:Level::Error, message:"Test error".to_owned(), code:Some("C000".to_owned()), spans: vec![sl, sl2] };
25
26 let sl3 = SpanLabel { span: var_span, style: SpanStyle::Primary, label:Some("variable".to_owned()) };
27 let d2 = Diagnostic { level:Level::Warning, message:"Test warning".to_owned(), code:Some("W000".to_owned()), spans: vec![sl3] };
28
29 let d3 = Diagnostic { level: Level::Help, message:"Help message".to_owned(), code: None, spans: vec![] };
30
31 let mut emitter = Emitter::stderr(ColorConfig::Auto, Some(&codemap));
32 emitter.emit(&[d1, d2, d3]);
33}
Auto Trait Implementations§
impl<'a, T> !Freeze for Emitter<'a, T>
impl<'a, T> !RefUnwindSafe for Emitter<'a, T>
impl<'a, T> Send for Emitter<'a, T>
impl<'a, T> !Sync for Emitter<'a, T>
impl<'a, T> Unpin for Emitter<'a, T>
impl<'a, T> !UnwindSafe for Emitter<'a, T>
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