diff --git a/src/packet.rs b/src/packet.rs index 7565205cd75b1a36589b5e38fac9a36869816b5e..6ad9e01630fde26843aff00f211de96a43497099 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -93,12 +93,17 @@ pub struct Packet<'a, const N: usize> { buf: Buffer<'a, N>, } -// TODO need a method for cloning packets impl<'a, const N: usize> Packet<'a, N> { pub fn new(buf: &'a mut [u8; N]) -> Self { Self { buf: buf.into() } } + pub fn clone_backing<'b>(&self, buf: &'b mut [u8; N]) -> Packet<'b, N> { + Packet { + buf: self.buf.clone_backing(buf), + } + } + /// Expects bytes in the `buf` /// `buf` is used as the backing buffer for the Packet pub fn decode(buf: Buffer<'a, N>) -> Result<Self, DecodeError> {