• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rust-lang / annotate-snippets-rs / 14500801022

16 Apr 2025 07:20PM UTC coverage: 87.161% (+1.3%) from 85.84%
14500801022

Pull #195

github

web-flow
Merge 353a04044 into 5e302a9f1
Pull Request #195: New api

1246 of 1415 new or added lines in 7 files covered. (88.06%)

2 existing lines in 1 file now uncovered.

1351 of 1550 relevant lines covered (87.16%)

3.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.83
/src/level.rs
1
use crate::renderer::stylesheet::Stylesheet;
2
use crate::snippet::{ERROR_TXT, HELP_TXT, INFO_TXT, NOTE_TXT, WARNING_TXT};
3
use crate::{Element, Group, Message, Title};
4
use anstyle::Style;
5

6
pub const ERROR: Level<'_> = Level {
7
    name: None,
8
    level: LevelInner::Error,
9
};
10

11
pub const WARNING: Level<'_> = Level {
12
    name: None,
13
    level: LevelInner::Warning,
14
};
15

16
pub const INFO: Level<'_> = Level {
17
    name: None,
18
    level: LevelInner::Info,
19
};
20

21
pub const NOTE: Level<'_> = Level {
22
    name: None,
23
    level: LevelInner::Note,
24
};
25

26
pub const HELP: Level<'_> = Level {
27
    name: None,
28
    level: LevelInner::Help,
29
};
30

31
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
32
pub struct Level<'a> {
33
    pub(crate) name: Option<Option<&'a str>>,
34
    pub(crate) level: LevelInner,
35
}
36

37
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
38
pub enum Level2<'a> {
39
    Builtin(LevelInner),
40
    Custom {
41
        name: Option<&'a str>,
42
        level: LevelInner,
43
    },
44
    None,
45
}
46

47
impl<'a> Level<'a> {
48
    pub const ERROR: Level<'a> = ERROR;
49
    pub const WARNING: Level<'a> = WARNING;
50
    pub const INFO: Level<'a> = INFO;
51
    pub const NOTE: Level<'a> = NOTE;
52
    pub const HELP: Level<'a> = HELP;
53

54
    /// Text passed to this function is considered "untrusted input", as such
55
    /// all text is passed through a normalization function. Pre-styled text is
56
    /// not allowed to be passed to this function.
NEW
57
    pub fn text(self, text: Option<&'a str>) -> Level<'a> {
×
58
        Level {
NEW
59
            name: Some(text),
×
NEW
60
            level: self.level,
×
61
        }
62
    }
63
}
64

65
impl<'a> Level<'a> {
66
    /// Text passed to this function is considered "untrusted input", as such
67
    /// all text is passed through a normalization function. Pre-styled text is
68
    /// not allowed to be passed to this function.
69
    pub fn message(self, title: &'a str) -> Message<'a> {
9✔
70
        Message {
71
            id: None,
72
            groups: vec![Group::new().element(Element::Title(Title {
8✔
73
                level: self,
74
                title,
75
                primary: true,
76
            }))],
77
        }
78
    }
79

80
    /// Text passed to this function is allowed to be pre-styled, as such all
81
    /// text is considered "trusted input" and has no normalizations applied to
82
    /// it. [`normalize_untrusted_str`](crate::normalize_untrusted_str) can be
83
    /// used to normalize untrusted text before it is passed to this function.
84
    pub fn title(self, title: &'a str) -> Title<'a> {
4✔
85
        Title {
86
            level: self,
87
            title,
88
            primary: false,
89
        }
90
    }
91

92
    pub(crate) fn as_str(&self) -> &'a str {
6✔
93
        match (self.name, self.level) {
4✔
NEW
94
            (Some(Some(name)), _) => name,
×
NEW
95
            (Some(None), _) => "",
×
96
            (None, LevelInner::Error) => ERROR_TXT,
5✔
97
            (None, LevelInner::Warning) => WARNING_TXT,
1✔
NEW
98
            (None, LevelInner::Info) => INFO_TXT,
×
99
            (None, LevelInner::Note) => NOTE_TXT,
2✔
100
            (None, LevelInner::Help) => HELP_TXT,
3✔
101
        }
102
    }
103

104
    pub(crate) fn style(&self, stylesheet: &Stylesheet) -> Style {
5✔
105
        self.level.style(stylesheet)
5✔
106
    }
107
}
108

109
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
110
pub enum LevelInner {
111
    Error,
112
    Warning,
113
    Info,
114
    Note,
115
    Help,
116
}
117

118
impl LevelInner {
119
    pub(crate) fn style(self, stylesheet: &Stylesheet) -> Style {
5✔
120
        match self {
3✔
121
            LevelInner::Error => stylesheet.error,
5✔
122
            LevelInner::Warning => stylesheet.warning,
1✔
NEW
123
            LevelInner::Info => stylesheet.info,
×
124
            LevelInner::Note => stylesheet.note,
2✔
125
            LevelInner::Help => stylesheet.help,
3✔
126
        }
127
    }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc