@@ -43,13 +43,71 @@ pub struct Level<'a> {
4343 pub ( crate ) level : LevelInner ,
4444}
4545
46+ /// # Constructors
4647impl < ' a > Level < ' a > {
4748 pub const ERROR : Level < ' a > = ERROR ;
4849 pub const WARNING : Level < ' a > = WARNING ;
4950 pub const INFO : Level < ' a > = INFO ;
5051 pub const NOTE : Level < ' a > = NOTE ;
5152 pub const HELP : Level < ' a > = HELP ;
53+ }
54+
55+ impl < ' a > Level < ' a > {
56+ /// A text [`Element`][crate::Element] to start a [`Group`][crate::Group]
57+ ///
58+ /// See [`Group::with_title`][crate::Group::with_title]
59+ ///
60+ /// <div class="warning">
61+ ///
62+ /// Text passed to this function is considered "untrusted input", as such
63+ /// all text is passed through a normalization function. Pre-styled text is
64+ /// not allowed to be passed to this function.
65+ ///
66+ /// </div>
67+ pub fn title ( self , text : impl Into < Cow < ' a , str > > ) -> Title < ' a > {
68+ Title {
69+ level : self ,
70+ id : None ,
71+ text : text. into ( ) ,
72+ }
73+ }
74+
75+ /// A text [`Element`][crate::Element] in a [`Group`][crate::Group]
76+ ///
77+ /// <div class="warning">
78+ ///
79+ /// Text passed to this function is allowed to be pre-styled, as such all
80+ /// text is considered "trusted input" and has no normalizations applied to
81+ /// it. [`normalize_untrusted_str`](crate::normalize_untrusted_str) can be
82+ /// used to normalize untrusted text before it is passed to this function.
83+ ///
84+ /// </div>
85+ pub fn message ( self , text : impl Into < Cow < ' a , str > > ) -> Message < ' a > {
86+ Message {
87+ level : self ,
88+ text : text. into ( ) ,
89+ }
90+ }
91+
92+ pub ( crate ) fn as_str ( & ' a self ) -> & ' a str {
93+ match ( & self . name , self . level ) {
94+ ( Some ( Some ( name) ) , _) => name. as_ref ( ) ,
95+ ( Some ( None ) , _) => "" ,
96+ ( None , LevelInner :: Error ) => ERROR_TXT ,
97+ ( None , LevelInner :: Warning ) => WARNING_TXT ,
98+ ( None , LevelInner :: Info ) => INFO_TXT ,
99+ ( None , LevelInner :: Note ) => NOTE_TXT ,
100+ ( None , LevelInner :: Help ) => HELP_TXT ,
101+ }
102+ }
103+
104+ pub ( crate ) fn style ( & self , stylesheet : & Stylesheet ) -> Style {
105+ self . level . style ( stylesheet)
106+ }
107+ }
52108
109+ /// # Customize the `Level`
110+ impl < ' a > Level < ' a > {
53111 /// Replace the name describing this [`Level`]
54112 ///
55113 /// <div class="warning">
@@ -111,60 +169,6 @@ impl<'a> Level<'a> {
111169 }
112170}
113171
114- impl < ' a > Level < ' a > {
115- /// A text [`Element`][crate::Element] to start a [`Group`][crate::Group]
116- ///
117- /// See [`Group::with_title`][crate::Group::with_title]
118- ///
119- /// <div class="warning">
120- ///
121- /// Text passed to this function is considered "untrusted input", as such
122- /// all text is passed through a normalization function. Pre-styled text is
123- /// not allowed to be passed to this function.
124- ///
125- /// </div>
126- pub fn title ( self , text : impl Into < Cow < ' a , str > > ) -> Title < ' a > {
127- Title {
128- level : self ,
129- id : None ,
130- text : text. into ( ) ,
131- }
132- }
133-
134- /// A text [`Element`][crate::Element] in a [`Group`][crate::Group]
135- ///
136- /// <div class="warning">
137- ///
138- /// Text passed to this function is allowed to be pre-styled, as such all
139- /// text is considered "trusted input" and has no normalizations applied to
140- /// it. [`normalize_untrusted_str`](crate::normalize_untrusted_str) can be
141- /// used to normalize untrusted text before it is passed to this function.
142- ///
143- /// </div>
144- pub fn message ( self , text : impl Into < Cow < ' a , str > > ) -> Message < ' a > {
145- Message {
146- level : self ,
147- text : text. into ( ) ,
148- }
149- }
150-
151- pub ( crate ) fn as_str ( & ' a self ) -> & ' a str {
152- match ( & self . name , self . level ) {
153- ( Some ( Some ( name) ) , _) => name. as_ref ( ) ,
154- ( Some ( None ) , _) => "" ,
155- ( None , LevelInner :: Error ) => ERROR_TXT ,
156- ( None , LevelInner :: Warning ) => WARNING_TXT ,
157- ( None , LevelInner :: Info ) => INFO_TXT ,
158- ( None , LevelInner :: Note ) => NOTE_TXT ,
159- ( None , LevelInner :: Help ) => HELP_TXT ,
160- }
161- }
162-
163- pub ( crate ) fn style ( & self , stylesheet : & Stylesheet ) -> Style {
164- self . level . style ( stylesheet)
165- }
166- }
167-
168172#[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
169173pub ( crate ) enum LevelInner {
170174 Error ,
0 commit comments