Skip to content

Commit

Permalink
primitives: implement AsRef and serde for ByteStr
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 5, 2023
1 parent 9baa1e8 commit f1cdb38
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions primitives/src/coding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@ impl<T> LenVarInt for VarIntArray<T> {
#[strict_type(lib = LIB_NAME_BITCOIN)]
#[wrapper(Deref, Index, RangeOps, BorrowSlice)]
#[wrapper_mut(DerefMut, IndexMut, RangeMut, BorrowSliceMut)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", transparent)
)]
pub struct ByteStr(VarIntArray<u8>);

impl AsRef<[u8]> for ByteStr {
fn as_ref(&self) -> &[u8] { self.0.as_slice() }
}

impl From<Vec<u8>> for ByteStr {
fn from(value: Vec<u8>) -> Self { Self(Confined::try_from(value).expect("u64 >= usize")) }
}
Expand Down

0 comments on commit f1cdb38

Please sign in to comment.