aboutsummaryrefslogtreecommitdiff
path: root/src/bytes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bytes.rs')
-rw-r--r--src/bytes.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bytes.rs b/src/bytes.rs
index 93ab84b..8ecc853 100644
--- a/src/bytes.rs
+++ b/src/bytes.rs
@@ -418,7 +418,15 @@ impl Bytes {
#[inline]
pub fn truncate(&mut self, len: usize) {
if len < self.len {
- self.len = len;
+ // The Vec "promotable" vtables do not store the capacity,
+ // so we cannot truncate while using this repr. We *have* to
+ // promote using `split_off` so the capacity can be stored.
+ if self.vtable as *const Vtable == &PROMOTABLE_EVEN_VTABLE ||
+ self.vtable as *const Vtable == &PROMOTABLE_ODD_VTABLE {
+ drop(self.split_off(len));
+ } else {
+ self.len = len;
+ }
}
}