@@ -365,7 +365,7 @@ pub enum AstNode {
365365}
366366
367367impl AstNode {
368- pub fn parse ( input : & [ & str ] ) -> ExprResult < Self > {
368+ pub fn parse ( input : & [ impl AsRef < str > ] ) -> ExprResult < Self > {
369369 Parser :: new ( input) . parse ( )
370370 }
371371
@@ -427,33 +427,33 @@ impl AstNode {
427427 }
428428}
429429
430- struct Parser < ' a > {
431- input : & ' a [ & ' a str ] ,
430+ struct Parser < ' a , S : AsRef < str > > {
431+ input : & ' a [ S ] ,
432432 index : usize ,
433433}
434434
435- impl < ' a > Parser < ' a > {
436- fn new ( input : & ' a [ & ' a str ] ) -> Self {
435+ impl < ' a , S : AsRef < str > > Parser < ' a , S > {
436+ fn new ( input : & ' a [ S ] ) -> Self {
437437 Self { input, index : 0 }
438438 }
439439
440440 fn next ( & mut self ) -> ExprResult < & ' a str > {
441441 let next = self . input . get ( self . index ) ;
442442 if let Some ( next) = next {
443443 self . index += 1 ;
444- Ok ( next)
444+ Ok ( next. as_ref ( ) )
445445 } else {
446446 // The indexing won't panic, because we know that the input size
447447 // is greater than zero.
448448 Err ( ExprError :: MissingArgument (
449- self . input [ self . index - 1 ] . into ( ) ,
449+ self . input [ self . index - 1 ] . as_ref ( ) . into ( ) ,
450450 ) )
451451 }
452452 }
453453
454454 fn accept < T > ( & mut self , f : impl Fn ( & str ) -> Option < T > ) -> Option < T > {
455455 let next = self . input . get ( self . index ) ?;
456- let tok = f ( next) ;
456+ let tok = f ( next. as_ref ( ) ) ;
457457 if let Some ( tok) = tok {
458458 self . index += 1 ;
459459 Some ( tok)
@@ -468,7 +468,7 @@ impl<'a> Parser<'a> {
468468 }
469469 let res = self . parse_expression ( ) ?;
470470 if let Some ( arg) = self . input . get ( self . index ) {
471- return Err ( ExprError :: UnexpectedArgument ( arg. to_string ( ) ) ) ;
471+ return Err ( ExprError :: UnexpectedArgument ( arg. as_ref ( ) . into ( ) ) ) ;
472472 }
473473 Ok ( res)
474474 }
@@ -556,12 +556,12 @@ impl<'a> Parser<'a> {
556556 // at `self.index - 1`. So this indexing won't panic.
557557 Ok ( _) => {
558558 return Err ( ExprError :: ExpectedClosingBraceInsteadOf (
559- self . input [ self . index - 1 ] . into ( ) ,
559+ self . input [ self . index - 1 ] . as_ref ( ) . into ( ) ,
560560 ) ) ;
561561 }
562562 Err ( ExprError :: MissingArgument ( _) ) => {
563563 return Err ( ExprError :: ExpectedClosingBraceAfter (
564- self . input [ self . index - 1 ] . into ( ) ,
564+ self . input [ self . index - 1 ] . as_ref ( ) . into ( ) ,
565565 ) ) ;
566566 }
567567 Err ( e) => return Err ( e) ,
0 commit comments