@@ -10,18 +10,27 @@ pub(crate) const INFO_TXT: &str = "info";
1010pub ( crate )  const  NOTE_TXT :  & str  = "note" ; 
1111pub ( crate )  const  WARNING_TXT :  & str  = "warning" ; 
1212
13+ /// Top-level user message 
1314#[ derive( Debug ) ]  
1415pub  struct  Message < ' a >  { 
1516    pub ( crate )  id :  Option < & ' a  str > ,  // for "correctness", could be sloppy and be on Title 
1617    pub ( crate )  groups :  Vec < Group < ' a > > , 
1718} 
1819
1920impl < ' a >  Message < ' a >  { 
21+     /// <div class="warning"> 
22+ /// 
23+ /// Text passed to this function is considered "untrusted input", as such 
24+ /// all text is passed through a normalization function. Pre-styled text is 
25+ /// not allowed to be passed to this function. 
26+ /// 
27+ /// </div> 
2028pub  fn  id ( mut  self ,  id :  & ' a  str )  -> Self  { 
2129        self . id  = Some ( id) ; 
2230        self 
2331    } 
2432
33+     /// Add an [`Element`] container 
2534pub  fn  group ( mut  self ,  group :  Group < ' a > )  -> Self  { 
2635        self . groups . push ( group) ; 
2736        self 
@@ -66,6 +75,7 @@ impl<'a> Message<'a> {
6675    } 
6776} 
6877
78+ /// An [`Element`] container 
6979#[ derive( Debug ) ]  
7080pub  struct  Group < ' a >  { 
7181    pub ( crate )  elements :  Vec < Element < ' a > > , 
@@ -97,6 +107,7 @@ impl<'a> Group<'a> {
97107    } 
98108} 
99109
110+ /// A section of content within a [`Group`] 
100111#[ derive( Debug ) ]  
101112#[ non_exhaustive]  
102113pub  enum  Element < ' a >  { 
@@ -137,9 +148,13 @@ impl From<Padding> for Element<'_> {
137148    } 
138149} 
139150
151+ /// A whitespace [`Element`] in a [`Group`] 
140152#[ derive( Debug ) ]  
141153pub  struct  Padding ; 
142154
155+ /// A text [`Element`] in a [`Group`] 
156+ /// 
157+ /// See [`Level::title`] to create this. 
143158#[ derive( Debug ) ]  
144159pub  struct  Title < ' a >  { 
145160    pub ( crate )  level :  Level < ' a > , 
@@ -154,6 +169,7 @@ impl Title<'_> {
154169    } 
155170} 
156171
172+ /// A source view [`Element`] in a [`Group`] 
157173#[ derive( Debug ) ]  
158174pub  struct  Snippet < ' a ,  T >  { 
159175    pub ( crate )  origin :  Option < & ' a  str > , 
@@ -164,9 +180,15 @@ pub struct Snippet<'a, T> {
164180} 
165181
166182impl < ' a ,  T :  Clone >  Snippet < ' a ,  T >  { 
183+     /// The source code to be rendered 
184+ /// 
185+ /// <div class="warning"> 
186+ /// 
167187/// Text passed to this function is considered "untrusted input", as such 
168188/// all text is passed through a normalization function. Pre-styled text is 
169189/// not allowed to be passed to this function. 
190+ /// 
191+ /// </div> 
170192pub  fn  source ( source :  & ' a  str )  -> Self  { 
171193        Self  { 
172194            origin :  None , 
@@ -177,49 +199,65 @@ impl<'a, T: Clone> Snippet<'a, T> {
177199        } 
178200    } 
179201
202+     /// When manually [`fold`][Self::fold]ing, 
203+ /// the [`source`][Self::source]s line offset from the original start 
180204pub  fn  line_start ( mut  self ,  line_start :  usize )  -> Self  { 
181205        self . line_start  = line_start; 
182206        self 
183207    } 
184208
209+     /// The location of the [`source`][Self::source] (e.g. a path) 
210+ /// 
211+ /// <div class="warning"> 
212+ /// 
185213/// Text passed to this function is considered "untrusted input", as such 
186214/// all text is passed through a normalization function. Pre-styled text is 
187215/// not allowed to be passed to this function. 
216+ /// 
217+ /// </div> 
188218pub  fn  origin ( mut  self ,  origin :  & ' a  str )  -> Self  { 
189219        self . origin  = Some ( origin) ; 
190220        self 
191221    } 
192222
223+     /// Hide lines without [`Annotation`]s 
193224pub  fn  fold ( mut  self ,  fold :  bool )  -> Self  { 
194225        self . fold  = fold; 
195226        self 
196227    } 
197228} 
198229
199230impl < ' a >  Snippet < ' a ,  Annotation < ' a > >  { 
231+     /// Highlight and describe a span of text within the [`source`][Self::source] 
200232pub  fn  annotation ( mut  self ,  annotation :  Annotation < ' a > )  -> Snippet < ' a ,  Annotation < ' a > >  { 
201233        self . markers . push ( annotation) ; 
202234        self 
203235    } 
204236
237+     /// Highlight and describe spans of text within the [`source`][Self::source] 
205238pub  fn  annotations ( mut  self ,  annotation :  impl  IntoIterator < Item  = Annotation < ' a > > )  -> Self  { 
206239        self . markers . extend ( annotation) ; 
207240        self 
208241    } 
209242} 
210243
211244impl < ' a >  Snippet < ' a ,  Patch < ' a > >  { 
245+     /// Suggest to the user an edit to the [`source`][Self::source] 
212246pub  fn  patch ( mut  self ,  patch :  Patch < ' a > )  -> Snippet < ' a ,  Patch < ' a > >  { 
213247        self . markers . push ( patch) ; 
214248        self 
215249    } 
216250
251+     /// Suggest to the user edits to the [`source`][Self::source] 
217252pub  fn  patches ( mut  self ,  patches :  impl  IntoIterator < Item  = Patch < ' a > > )  -> Self  { 
218253        self . markers . extend ( patches) ; 
219254        self 
220255    } 
221256} 
222257
258+ /// Highlighted and describe a span of text within a [`Snippet`] 
259+ /// 
260+ /// See [`AnnotationKind`] to create an annotation. 
223261#[ derive( Clone ,  Debug ) ]  
224262pub  struct  Annotation < ' a >  { 
225263    pub ( crate )  span :  Range < usize > , 
@@ -229,20 +267,30 @@ pub struct Annotation<'a> {
229267} 
230268
231269impl < ' a >  Annotation < ' a >  { 
270+     /// Describe the reason the span is highlighted 
271+ /// 
272+ /// This will be styled according to the [`AnnotationKind`] 
273+ /// 
274+ /// <div class="warning"> 
275+ /// 
232276/// Text passed to this function is considered "untrusted input", as such 
233277/// all text is passed through a normalization function. Pre-styled text is 
234278/// not allowed to be passed to this function. 
279+ /// 
280+ /// </div> 
235281pub  fn  label ( mut  self ,  label :  & ' a  str )  -> Self  { 
236282        self . label  = Some ( label) ; 
237283        self 
238284    } 
239285
286+     /// Style the source according to the [`AnnotationKind`] 
240287pub  fn  highlight_source ( mut  self ,  highlight_source :  bool )  -> Self  { 
241288        self . highlight_source  = highlight_source; 
242289        self 
243290    } 
244291} 
245292
293+ /// The category of the [`Annotation`] 
246294#[ derive( Clone ,  Copy ,  Debug ,  PartialEq ,  Eq ,  PartialOrd ,  Ord ) ]  
247295pub  enum  AnnotationKind  { 
248296    /// Color to [`Message`]'s [`Level`] 
@@ -266,16 +314,23 @@ impl AnnotationKind {
266314    } 
267315} 
268316
317+ /// Suggested edit to the [`Snippet`] 
269318#[ derive( Clone ,  Debug ) ]  
270319pub  struct  Patch < ' a >  { 
271320    pub ( crate )  span :  Range < usize > , 
272321    pub ( crate )  replacement :  & ' a  str , 
273322} 
274323
275324impl < ' a >  Patch < ' a >  { 
325+     /// Splice `replacement` into the [`Snippet`] at the `span` 
326+ /// 
327+ /// <div class="warning"> 
328+ /// 
276329/// Text passed to this function is considered "untrusted input", as such 
277330/// all text is passed through a normalization function. Pre-styled text is 
278331/// not allowed to be passed to this function. 
332+ /// 
333+ /// </div> 
279334pub  fn  new ( span :  Range < usize > ,  replacement :  & ' a  str )  -> Self  { 
280335        Self  {  span,  replacement } 
281336    } 
@@ -328,6 +383,7 @@ impl<'a> Patch<'a> {
328383    } 
329384} 
330385
386+ /// The location of the [`Snippet`] (e.g. a path) 
331387#[ derive( Clone ,  Debug ) ]  
332388pub  struct  Origin < ' a >  { 
333389    pub ( crate )  origin :  & ' a  str , 
@@ -338,9 +394,13 @@ pub struct Origin<'a> {
338394} 
339395
340396impl < ' a >  Origin < ' a >  { 
397+     /// <div class="warning"> 
398+ /// 
341399/// Text passed to this function is considered "untrusted input", as such 
342400/// all text is passed through a normalization function. Pre-styled text is 
343401/// not allowed to be passed to this function. 
402+ /// 
403+ /// </div> 
344404pub  fn  new ( origin :  & ' a  str )  -> Self  { 
345405        Self  { 
346406            origin, 
@@ -351,11 +411,17 @@ impl<'a> Origin<'a> {
351411        } 
352412    } 
353413
414+     /// Set the default line number to display 
415+ /// 
416+ /// Otherwise this will be inferred from the primary [`Annotation`] 
354417pub  fn  line ( mut  self ,  line :  usize )  -> Self  { 
355418        self . line  = Some ( line) ; 
356419        self 
357420    } 
358421
422+     /// Set the default column to display 
423+ /// 
424+ /// Otherwise this will be inferred from the primary [`Annotation`] 
359425pub  fn  char_column ( mut  self ,  char_column :  usize )  -> Self  { 
360426        self . char_column  = Some ( char_column) ; 
361427        self 
@@ -366,9 +432,15 @@ impl<'a> Origin<'a> {
366432        self 
367433    } 
368434
435+     /// Like [`Annotation::label`], but when there is no source 
436+ /// 
437+ /// <div class="warning"> 
438+ /// 
369439/// Text passed to this function is considered "untrusted input", as such 
370440/// all text is passed through a normalization function. Pre-styled text is 
371441/// not allowed to be passed to this function. 
442+ /// 
443+ /// </div> 
372444pub  fn  label ( mut  self ,  label :  & ' a  str )  -> Self  { 
373445        self . label  = Some ( label) ; 
374446        self 
0 commit comments