]> git.proxmox.com Git - rustc.git/blame - vendor/annotate-snippets/src/formatter/style.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / vendor / annotate-snippets / src / formatter / style.rs
CommitLineData
f035d41b 1//! Set of structures required to implement a stylesheet
dc9dc135
XL
2//!
3//! In order to provide additional styling information for the
4//! formatter, a structs can implement `Stylesheet` and `Style`
5//! traits.
6//!
f035d41b 7use std::fmt;
dc9dc135
XL
8
9/// StyleClass is a collection of named variants of style classes
dc9dc135
XL
10pub enum StyleClass {
11 /// Message indicating an error.
12 Error,
13 /// Message indicating a warning.
14 Warning,
15 /// Message indicating an information.
16 Info,
17 /// Message indicating a note.
18 Note,
19 /// Message indicating a help.
20 Help,
21
22 /// Style for line numbers.
23 LineNo,
24
25 /// Parts of the text that are to be emphasised.
26 Emphasis,
27
28 /// Parts of the text that are regular. Usually a no-op.
29 None,
30}
31
32/// This trait implements a return value for the `Stylesheet::get_style`.
33pub trait Style {
f035d41b
XL
34 /// The method used to write text with formatter
35 fn paint(&self, text: &str, f: &mut fmt::Formatter<'_>) -> fmt::Result;
36 /// The method used to write display function with formatter
37 fn paint_fn<'a>(
38 &self,
39 c: Box<dyn FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result + 'a>,
40 f: &mut fmt::Formatter<'_>,
41 ) -> fmt::Result;
dc9dc135
XL
42 /// The method used by the DisplayListFormatter to display the message
43 /// in bold font.
416331ca 44 fn bold(&self) -> Box<dyn Style>;
dc9dc135
XL
45}
46
47/// Trait to annotate structs that can provide `Style` implementations for
48/// every `StyleClass` variant.
49pub trait Stylesheet {
50 /// Returns a `Style` implementer based on the requested `StyleClass` variant.
416331ca 51 fn get_style(&self, class: StyleClass) -> Box<dyn Style>;
dc9dc135 52}