From ee7360a4d6f0e81a7837abfee0eace82cfe56296 Mon Sep 17 00:00:00 2001 From: Aljoscha Meyer Date: Thu, 8 Aug 2024 21:02:20 +0200 Subject: [PATCH] Fix IntoVec::into_vec --- ufotofu/src/common/consumer/into_vec.rs | 6 +++--- ufotofu/src/common/consumer/into_vec_fallible.rs | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ufotofu/src/common/consumer/into_vec.rs b/ufotofu/src/common/consumer/into_vec.rs index 68b0921..5115e4d 100644 --- a/ufotofu/src/common/consumer/into_vec.rs +++ b/ufotofu/src/common/consumer/into_vec.rs @@ -175,11 +175,11 @@ mod tests { #[test] fn converts_into_vec() { let mut into_vec = IntoVec::new(); - let _ = into_vec.bulk_consume(b"ufotofu"); + let _ = into_vec.bulk_consume_full_slice(b"ufotofu"); let _ = into_vec.close(()); - let vec = into_vec.into_vec(); - assert_eq!(vec.len(), 7); + let v = into_vec.into_vec(); + assert_eq!(v, std::vec![117, 102, 111, 116, 111, 102, 117]); } // Panic conditions: diff --git a/ufotofu/src/common/consumer/into_vec_fallible.rs b/ufotofu/src/common/consumer/into_vec_fallible.rs index a58899d..6e5ee8e 100644 --- a/ufotofu/src/common/consumer/into_vec_fallible.rs +++ b/ufotofu/src/common/consumer/into_vec_fallible.rs @@ -79,7 +79,9 @@ impl AsMut> for IntoVecFallible { impl Wrapper> for IntoVecFallible { fn into_inner(self) -> Vec { - self.v + let IntoVecFallible { mut v, consumed } = self; + v.truncate(consumed); + v } } @@ -153,11 +155,11 @@ mod tests { #[test] fn converts_into_vec() { let mut into_vec = IntoVecFallible::new(); - let _ = into_vec.bulk_consume(b"ufotofu"); + let _ = into_vec.bulk_consume_full_slice(b"ufotofu"); let _ = into_vec.close(()); - let vec = into_vec.into_vec(); - assert_eq!(vec.len(), 7); + let v = into_vec.into_vec(); + assert_eq!(v, std::vec![117, 102, 111, 116, 111, 102, 117]); } // Panic conditions: