1#[derive(Debug, Default)]
3pub struct Body {
4 bytes: Vec<u8>,
5}
6
7impl Body {
8 pub fn empty() -> Self {
10 Self::default()
11 }
12
13 pub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Self {
15 Self {
16 bytes: bytes.into(),
17 }
18 }
19
20 pub fn as_bytes(&self) -> &[u8] {
22 &self.bytes
23 }
24
25 pub fn len(&self) -> usize {
27 self.bytes.len()
28 }
29
30 pub fn is_empty(&self) -> bool {
32 self.bytes.is_empty()
33 }
34
35 pub fn into_bytes(self) -> Vec<u8> {
37 self.bytes
38 }
39}
40
41impl From<Vec<u8>> for Body {
42 fn from(bytes: Vec<u8>) -> Self {
43 Self::from_bytes(bytes)
44 }
45}
46
47impl From<&[u8]> for Body {
48 fn from(bytes: &[u8]) -> Self {
49 Self::from_bytes(bytes)
50 }
51}
52
53impl From<String> for Body {
54 fn from(value: String) -> Self {
55 Self::from_bytes(value.into_bytes())
56 }
57}
58
59impl From<&str> for Body {
60 fn from(value: &str) -> Self {
61 Self::from_bytes(value.as_bytes())
62 }
63}