@@ -97,6 +97,18 @@ pub trait Read<'de>: private::Sealed {
9797 fn end_raw_buffering < V > ( & mut self , visitor : V ) -> Result < V :: Value >
9898 where
9999 V : Visitor < ' de > ;
100+
101+ /// Whether StreamDeserializer::next needs to check the failed flag. True
102+ /// for IoRead, false for StrRead and SliceRead which can track failure by
103+ /// truncating their input slice to avoid the extra check on every next
104+ /// call.
105+ #[ doc( hidden) ]
106+ const should_early_return_if_failed: bool ;
107+
108+ /// Mark a persistent failure of StreamDeserializer, either by setting the
109+ /// flag or by truncating the input data.
110+ #[ doc( hidden) ]
111+ fn set_failed ( & mut self , failed : & mut bool ) ;
100112}
101113
102114pub struct Position {
@@ -379,6 +391,13 @@ where
379391 raw_value : Some ( raw) ,
380392 } )
381393 }
394+
395+ const should_early_return_if_failed: bool = true ;
396+
397+ #[ inline]
398+ fn set_failed ( & mut self , failed : & mut bool ) {
399+ * failed = true ;
400+ }
382401}
383402
384403//////////////////////////////////////////////////////////////////////////////
@@ -590,6 +609,13 @@ impl<'a> Read<'a> for SliceRead<'a> {
590609 raw_value : Some ( raw) ,
591610 } )
592611 }
612+
613+ const should_early_return_if_failed: bool = false ;
614+
615+ #[ inline]
616+ fn set_failed ( & mut self , _failed : & mut bool ) {
617+ self . slice = & self . slice [ ..self . index ] ;
618+ }
593619}
594620
595621//////////////////////////////////////////////////////////////////////////////
@@ -681,6 +707,13 @@ impl<'a> Read<'a> for StrRead<'a> {
681707 raw_value : Some ( raw) ,
682708 } )
683709 }
710+
711+ const should_early_return_if_failed: bool = false ;
712+
713+ #[ inline]
714+ fn set_failed ( & mut self , failed : & mut bool ) {
715+ self . delegate . set_failed ( failed) ;
716+ }
684717}
685718
686719//////////////////////////////////////////////////////////////////////////////
0 commit comments