From b9c11b56f8092f437739e17d4c3fcbfbbd28fa5c Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 23 Oct 2017 23:49:27 -0700 Subject: [PATCH] added shared string body --- src/body.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/body.rs b/src/body.rs index c4ce4a081..3bdc975e9 100644 --- a/src/body.rs +++ b/src/body.rs @@ -29,9 +29,14 @@ pub enum BinaryBody { Slice(&'static [u8]), /// Shared bytes body SharedBytes(Rc), + /// Shared stirng body + SharedString(Rc), /// Shared bytes body #[doc(hidden)] ArcSharedBytes(Arc), + /// Shared string body + #[doc(hidden)] + ArcSharedString(Arc), } impl Body { @@ -62,6 +67,8 @@ impl BinaryBody { &BinaryBody::Slice(slice) => slice.len(), &BinaryBody::SharedBytes(ref bytes) => bytes.len(), &BinaryBody::ArcSharedBytes(ref bytes) => bytes.len(), + &BinaryBody::SharedString(ref s) => s.len(), + &BinaryBody::ArcSharedString(ref s) => s.len(), } } @@ -131,6 +138,30 @@ impl<'a> From<&'a Arc> for BinaryBody { } } +impl From> for BinaryBody { + fn from(body: Rc) -> BinaryBody { + BinaryBody::SharedString(body) + } +} + +impl<'a> From<&'a Rc> for BinaryBody { + fn from(body: &'a Rc) -> BinaryBody { + BinaryBody::SharedString(Rc::clone(body)) + } +} + +impl From> for BinaryBody { + fn from(body: Arc) -> BinaryBody { + BinaryBody::ArcSharedString(body) + } +} + +impl<'a> From<&'a Arc> for BinaryBody { + fn from(body: &'a Arc) -> BinaryBody { + BinaryBody::ArcSharedString(Arc::clone(body)) + } +} + impl AsRef<[u8]> for BinaryBody { fn as_ref(&self) -> &[u8] { match self { @@ -138,6 +169,8 @@ impl AsRef<[u8]> for BinaryBody { &BinaryBody::Slice(slice) => slice, &BinaryBody::SharedBytes(ref bytes) => bytes.as_ref(), &BinaryBody::ArcSharedBytes(ref bytes) => bytes.as_ref(), + &BinaryBody::SharedString(ref s) => s.as_bytes(), + &BinaryBody::ArcSharedString(ref s) => s.as_bytes(), } } }