1use std::borrow::Cow;
2use std::ops::Deref;
3
4pub struct Frame<'a> {
6 data: Cow<'a, [u8]>,
7}
8
9impl<'a> Frame<'a> {
10 pub fn new_borrowed(data: &'a [u8]) -> Self {
12 Self {
13 data: Cow::Borrowed(data),
14 }
15 }
16
17 pub fn new_owned(data: Vec<u8>) -> Self {
19 Self {
20 data: Cow::Owned(data),
21 }
22 }
23
24 pub fn len(&self) -> usize {
26 self.data.len()
27 }
28
29 pub fn is_empty(&self) -> bool {
31 self.data.is_empty()
32 }
33
34 pub fn payload(&self) -> &[u8] {
36 self.data.as_ref()
37 }
38}
39
40impl Deref for Frame<'_> {
41 type Target = [u8];
42
43 fn deref(&self) -> &Self::Target {
44 self.data.as_ref()
45 }
46}
47impl<'a> From<&'a [u8]> for Frame<'a> {
48 fn from(data: &'a [u8]) -> Self {
49 Self::new_borrowed(data)
50 }
51}