Skip to content

Commit

Permalink
feat(zenoh_id): exposing into vec & try from slice
Browse files Browse the repository at this point in the history
Allowing users to create a ZenohId from a slice, using TryFrom, and also
allowing users to convert a ZenohId into a vector of bytes.
  • Loading branch information
DariusIMP committed Sep 6, 2024
1 parent 6b7ec55 commit 492e908
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions commons/zenoh-config/src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ impl From<ZenohIdProto> for ZenohId {
}
}

impl TryFrom<&[u8]> for ZenohId {
type Error = zenoh_result::Error;

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
let proto: ZenohIdProto = value.try_into()?;
Ok(ZenohId::from(proto))
}
}

impl From<ZenohId> for ZenohIdProto {
fn from(id: ZenohId) -> Self {
id.0
Expand All @@ -72,6 +81,13 @@ impl From<ZenohId> for OwnedKeyExpr {
}
}

impl From<ZenohId> for Vec<u8> {
fn from(value: ZenohId) -> Self {
let proto: ZenohIdProto = value.into();
proto.to_le_bytes().to_vec()
}
}

impl From<&ZenohId> for OwnedKeyExpr {
fn from(zid: &ZenohId) -> Self {
(*zid).into()
Expand Down

0 comments on commit 492e908

Please sign in to comment.