1+ //! [`Level`] constants for easy importing
2+
13use crate :: renderer:: stylesheet:: Stylesheet ;
24use crate :: snippet:: { ERROR_TXT , HELP_TXT , INFO_TXT , NOTE_TXT , WARNING_TXT } ;
35use crate :: { Element , Group , Message , Title } ;
46use anstyle:: Style ;
57
8+ /// Default `error:` [`Level`]
69pub const ERROR : Level < ' _ > = Level {
710 name : None ,
811 level : LevelInner :: Error ,
912} ;
1013
14+ /// Default `warning:` [`Level`]
1115pub const WARNING : Level < ' _ > = Level {
1216 name : None ,
1317 level : LevelInner :: Warning ,
1418} ;
1519
20+ /// Default `info:` [`Level`]
1621pub const INFO : Level < ' _ > = Level {
1722 name : None ,
1823 level : LevelInner :: Info ,
1924} ;
2025
26+ /// Default `note:` [`Level`]
2127pub const NOTE : Level < ' _ > = Level {
2228 name : None ,
2329 level : LevelInner :: Note ,
2430} ;
2531
32+ /// Default `help:` [`Level`]
2633pub const HELP : Level < ' _ > = Level {
2734 name : None ,
2835 level : LevelInner :: Help ,
2936} ;
3037
38+ /// [`Message`] or [`Title`] severity level
3139#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
3240pub struct Level < ' a > {
3341 pub ( crate ) name : Option < Option < & ' a str > > ,
3442 pub ( crate ) level : LevelInner ,
3543}
3644
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-
4745impl < ' a > Level < ' a > {
4846 pub const ERROR : Level < ' a > = ERROR ;
4947 pub const WARNING : Level < ' a > = WARNING ;
5048 pub const INFO : Level < ' a > = INFO ;
5149 pub const NOTE : Level < ' a > = NOTE ;
5250 pub const HELP : Level < ' a > = HELP ;
5351
52+ /// <div class="warning">
53+ ///
5454 /// Text passed to this function is considered "untrusted input", as such
5555 /// all text is passed through a normalization function. Pre-styled text is
5656 /// not allowed to be passed to this function.
57+ ///
58+ /// </div>
5759 pub fn text ( self , text : Option < & ' a str > ) -> Level < ' a > {
5860 Level {
5961 name : Some ( text) ,
@@ -63,24 +65,32 @@ impl<'a> Level<'a> {
6365}
6466
6567impl < ' a > Level < ' a > {
68+ /// <div class="warning">
69+ ///
6670 /// Text passed to this function is considered "untrusted input", as such
6771 /// all text is passed through a normalization function. Pre-styled text is
6872 /// not allowed to be passed to this function.
69- pub fn message ( self , title : & ' a str ) -> Message < ' a > {
73+ ///
74+ /// </div>
75+ pub fn header ( self , header : & ' a str ) -> Message < ' a > {
7076 Message {
7177 id : None ,
7278 groups : vec ! [ Group :: new( ) . element( Element :: Title ( Title {
7379 level: self ,
74- title,
80+ title: header ,
7581 primary: true ,
7682 } ) ) ] ,
7783 }
7884 }
7985
86+ /// <div class="warning">
87+ ///
8088 /// Text passed to this function is allowed to be pre-styled, as such all
8189 /// text is considered "trusted input" and has no normalizations applied to
8290 /// it. [`normalize_untrusted_str`](crate::normalize_untrusted_str) can be
8391 /// used to normalize untrusted text before it is passed to this function.
92+ ///
93+ /// </div>
8494 pub fn title ( self , title : & ' a str ) -> Title < ' a > {
8595 Title {
8696 level : self ,
@@ -107,7 +117,7 @@ impl<'a> Level<'a> {
107117}
108118
109119#[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
110- pub enum LevelInner {
120+ pub ( crate ) enum LevelInner {
111121 Error ,
112122 Warning ,
113123 Info ,
0 commit comments