Skip to content

Commit

Permalink
Merge pull request #73 from overhacked/overhacked/unparsed-asref
Browse files Browse the repository at this point in the history
Implement `AsRef<[u8]>` and `into_bytes(self)` for `Unparsed`
  • Loading branch information
baloo authored May 19, 2024
2 parents 0a509e6 + f0441f7 commit 874e986
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/proto/message/unparsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ impl Unparsed {
let mut v = &self.0[..];
T::decode(&mut v)
}

/// Obtain the unparsed bytes as a `Vec<u8>`, consuming the `Unparsed`
pub fn into_bytes(self) -> Vec<u8> {
self.0
}
}

impl From<Vec<u8>> for Unparsed {
Expand All @@ -24,6 +29,12 @@ impl From<Vec<u8>> for Unparsed {
}
}

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

impl Encode for Unparsed {
fn encoded_len(&self) -> ssh_encoding::Result<usize> {
Ok(self.0.len())
Expand Down

0 comments on commit 874e986

Please sign in to comment.