File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,22 @@ impl Hir {
322
322
/// let expected = HirKind::Literal(Literal(Box::from("☃".as_bytes())));
323
323
/// assert_eq!(&expected, concat.kind());
324
324
/// ```
325
+ ///
326
+ /// # Example: building a literal from a `char`
327
+ ///
328
+ /// This example shows how to build a single `Hir` literal from a `char`
329
+ /// value. Since a [`Literal`] is just bytes, we just need to UTF-8
330
+ /// encode a `char` value:
331
+ ///
332
+ /// ```
333
+ /// use regex_syntax::hir::{Hir, HirKind, Literal};
334
+ ///
335
+ /// let ch = '☃';
336
+ /// let got = Hir::literal(ch.encode_utf8(&mut [0; 4]).as_bytes());
337
+ ///
338
+ /// let expected = HirKind::Literal(Literal(Box::from("☃".as_bytes())));
339
+ /// assert_eq!(&expected, got.kind());
340
+ /// ```
325
341
#[ inline]
326
342
pub fn literal < B : Into < Box < [ u8 ] > > > ( lit : B ) -> Hir {
327
343
let bytes = lit. into ( ) ;
You can’t perform that action at this time.
0 commit comments