Skip to content

Commit

Permalink
impl From<Bytes> and From<Vec<u8>> for BytesMut
Browse files Browse the repository at this point in the history
`From<Bytes>` implementation is suboptimal: can be optimized for
certain representations of `Bytes`.
  • Loading branch information
stepancheg committed Mar 2, 2021
1 parent 2428c15 commit 599d089
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,19 @@ impl<'a> From<&'a str> for BytesMut {
}
}

impl From<Vec<u8>> for BytesMut {
fn from(src: Vec<u8>) -> BytesMut {
BytesMut::from_vec(src)
}
}

impl From<Bytes> for BytesMut {
fn from(src: Bytes) -> BytesMut {
// TODO: can be optimized for certain `Bytes` representations
BytesMut::from(src.as_ref())
}
}

impl From<BytesMut> for Bytes {
fn from(src: BytesMut) -> Bytes {
src.freeze()
Expand Down

0 comments on commit 599d089

Please sign in to comment.