impl `From` for `Cow<'static, [u8]>` for `Binary`

This commit is contained in:
Bernardo 2018-12-01 16:00:45 +01:00
parent c386353337
commit f87ffa6016
1 changed files with 10 additions and 0 deletions

View File

@ -1,5 +1,6 @@
use bytes::{Bytes, BytesMut};
use futures::Stream;
use std::borrow::Cow;
use std::sync::Arc;
use std::{fmt, mem};
@ -194,6 +195,15 @@ impl From<Vec<u8>> for Binary {
}
}
impl From<Cow<'static, [u8]>> for Binary {
fn from(b: Cow<'static, [u8]>) -> Binary {
match b {
Cow::Borrowed(s) => Binary::Slice(s),
Cow::Owned(vec) => Binary::Bytes(Bytes::from(vec)),
}
}
}
impl From<String> for Binary {
fn from(s: String) -> Binary {
Binary::Bytes(Bytes::from(s))