Move debug assertion.

This commit is contained in:
Todd Mortimer 2021-04-08 20:08:51 -04:00
parent 4232c773b5
commit 08de3362b4

View file

@ -157,24 +157,26 @@ impl<'a, T: Read + Write + 'a> Handle<'a, T> {
if !callback(response) { if !callback(response) {
break Ok(WaitOutcome::MailboxChanged); break Ok(WaitOutcome::MailboxChanged);
} }
if rest.is_empty() {
v.clear();
} else {
// Assert on partial parse in debug builds - we expect // Assert on partial parse in debug builds - we expect
// to always parse all or none of the input buffer. // to always parse all or none of the input buffer.
// On release builds, we still do the right thing. // On release builds, we still do the right thing.
debug_assert!( debug_assert!(
rest.len() != v.len(), rest.is_empty(),
"Unexpected partial parse: input: {:?}, output: {:?}", "Unexpected partial parse: input: {:?}, output: {:?}",
v, v,
rest rest,
); );
if rest.is_empty() {
v.clear();
} else {
let used = v.len() - rest.len(); let used = v.len() - rest.len();
v.drain(0..used); v.drain(0..used);
} }
} }
// Incomplete parse - do nothing and read more. // Incomplete parse - do nothing and read more.
(_rest, None) => (), (_rest, None) => {}
} }
} }
Err(r) => break Err(r), Err(r) => break Err(r),