1+ use crate :: map_decorator:: { MapDecorator , MapDecoratorMarker } ;
12use crate :: { InputTrait , Parser } ;
23
34pub struct AndThenParser < P , F > {
@@ -11,19 +12,25 @@ impl<P, F> AndThenParser<P, F> {
1112 }
1213}
1314
14- impl < I , C , P , F , U > Parser < I , C > for AndThenParser < P , F >
15+ impl < I , C , P , F , U > MapDecorator < I , C > for AndThenParser < P , F >
1516where
1617 I : InputTrait ,
1718 P : Parser < I , C > ,
1819 F : Fn ( P :: Output ) -> Result < U , P :: Error > ,
1920{
21+ type OriginalOutput = P :: Output ;
2022 type Output = U ;
2123 type Error = P :: Error ;
22- fn parse ( & mut self , tokenizer : & mut I ) -> Result < Self :: Output , Self :: Error > {
23- self . parser . parse ( tokenizer) . and_then ( & self . mapper )
24+
25+ fn decorated (
26+ & mut self ,
27+ ) -> & mut impl Parser < I , C , Output = Self :: OriginalOutput , Error = Self :: Error > {
28+ & mut self . parser
2429 }
2530
26- fn set_context ( & mut self , ctx : & C ) {
27- self . parser . set_context ( ctx )
31+ fn map_ok ( & self , ok : Self :: OriginalOutput ) -> Result < Self :: Output , Self :: Error > {
32+ ( self . mapper ) ( ok )
2833 }
2934}
35+
36+ impl < P , F > MapDecoratorMarker for AndThenParser < P , F > { }
0 commit comments