Skip to content

Commit

Permalink
Merge pull request #5 from wasmerio/from-cow
Browse files Browse the repository at this point in the history
feat: Add a `From<Cow<'_, [u8]>>` impl for `OwnedBuffer`
  • Loading branch information
Michael Bryan authored Dec 14, 2023
2 parents cbf635f + deda0e5 commit f7be4c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ change, where applicable.

## [Unreleased] - ReleaseDate

### Added

- Added a `From<Cow<'_, [u8]>>` impl for `OwnedBuffer` ([#5](https://github.com/wasmerio/shared-buffer/pull/5)

## [0.1.3] - 2023-06-07

- Added an `impl From<OwnedBuffer> for Vec<u8>`
Expand Down
10 changes: 10 additions & 0 deletions src/owned.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
borrow::Cow,
fs::File,
hash::Hash,
ops::{Deref, Index, RangeBounds},
Expand Down Expand Up @@ -249,6 +250,15 @@ impl From<&[u8]> for OwnedBuffer {
}
}

impl From<Cow<'_, [u8]>> for OwnedBuffer {
fn from(value: Cow<'_, [u8]>) -> Self {
match value {
Cow::Borrowed(value) => value.into(),
Cow::Owned(value) => value.into(),
}
}
}

impl From<Vec<u8>> for OwnedBuffer {
fn from(value: Vec<u8>) -> Self {
Bytes::from(value).into()
Expand Down

0 comments on commit f7be4c9

Please sign in to comment.