From 9aa24ebea1b3b6de824a6bb3236edf07605cae06 Mon Sep 17 00:00:00 2001 From: Carl Lerche <me@carllerche.com> Date: Thu, 30 Mar 2017 14:49:30 -0700 Subject: [PATCH] Bytes: only the vec repr is not shared (#100) The shared debug_assert is to ensure that the internal Bytes representation is such that offset views are supported. The only representation that does not support offset views is vec. Fixes #97 --- src/bytes.rs | 4 ++-- tests/test_bytes.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bytes.rs b/src/bytes.rs index 789fded..20af871 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -1890,8 +1890,8 @@ impl Inner { #[inline] fn is_shared(&mut self) -> bool { match self.kind() { - KIND_INLINE | KIND_ARC => true, - _ => false, + KIND_VEC => false, + _ => true, } } diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index e1938ed..1a3435f 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -363,6 +363,15 @@ fn extend() { assert_eq!(*bytes, LONG[..]); } +#[test] +fn from_static() { + let mut a = Bytes::from_static(b"ab"); + let b = a.split_off(1); + + assert_eq!(a, b"a"[..]); + assert_eq!(b, b"b"[..]); +} + #[test] // Only run these tests on little endian systems. CI uses qemu for testing // little endian... and qemu doesn't really support threading all that well. -- GitLab