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(data: &'a [u8]) -> Self {
12 Self {
13 data: Cow::Borrowed(data),
14 }
15 }
16
17 pub fn new_borrowed(data: &'a [u8]) -> Self {
20 Self::new(data)
21 }
22
23 pub fn new_owned(data: Vec<u8>) -> Self {
25 Self {
26 data: Cow::Owned(data),
27 }
28 }
29
30 pub fn len(&self) -> usize {
32 self.data.len()
33 }
34
35 pub fn is_empty(&self) -> bool {
37 self.data.is_empty()
38 }
39
40 pub fn payload(&self) -> &[u8] {
42 self.data.as_ref()
43 }
44}
45
46impl Deref for Frame<'_> {
47 type Target = [u8];
48
49 fn deref(&self) -> &Self::Target {
50 self.data.as_ref()
51 }
52}
53
54impl<'a> From<&'a [u8]> for Frame<'a> {
55 fn from(data: &'a [u8]) -> Self {
56 Self::new(data)
57 }
58}