bytes_expand/buf/
into_buf.rs1use super::{Buf};
2
3use std::io;
4
5pub trait IntoBuf {
27 type Buf: Buf;
29
30 fn into_buf(self) -> Self::Buf;
48}
49
50impl<T: Buf> IntoBuf for T {
51 type Buf = Self;
52
53 fn into_buf(self) -> Self {
54 self
55 }
56}
57
58impl<'a> IntoBuf for &'a [u8] {
59 type Buf = io::Cursor<&'a [u8]>;
60
61 fn into_buf(self) -> Self::Buf {
62 io::Cursor::new(self)
63 }
64}
65
66impl<'a> IntoBuf for &'a mut [u8] {
67 type Buf = io::Cursor<&'a mut [u8]>;
68
69 fn into_buf(self) -> Self::Buf {
70 io::Cursor::new(self)
71 }
72}
73
74impl<'a> IntoBuf for &'a str {
75 type Buf = io::Cursor<&'a [u8]>;
76
77 fn into_buf(self) -> Self::Buf {
78 self.as_bytes().into_buf()
79 }
80}
81
82impl IntoBuf for Vec<u8> {
83 type Buf = io::Cursor<Vec<u8>>;
84
85 fn into_buf(self) -> Self::Buf {
86 io::Cursor::new(self)
87 }
88}
89
90impl<'a> IntoBuf for &'a Vec<u8> {
91 type Buf = io::Cursor<&'a [u8]>;
92
93 fn into_buf(self) -> Self::Buf {
94 io::Cursor::new(&self[..])
95 }
96}
97
98impl<'a> IntoBuf for &'a &'static [u8] {
101 type Buf = io::Cursor<&'static [u8]>;
102
103 fn into_buf(self) -> Self::Buf {
104 io::Cursor::new(self)
105 }
106}
107
108impl<'a> IntoBuf for &'a &'static str {
109 type Buf = io::Cursor<&'static [u8]>;
110
111 fn into_buf(self) -> Self::Buf {
112 self.as_bytes().into_buf()
113 }
114}
115
116impl IntoBuf for String {
117 type Buf = io::Cursor<Vec<u8>>;
118
119 fn into_buf(self) -> Self::Buf {
120 self.into_bytes().into_buf()
121 }
122}
123
124impl<'a> IntoBuf for &'a String {
125 type Buf = io::Cursor<&'a [u8]>;
126
127 fn into_buf(self) -> Self::Buf {
128 self.as_bytes().into_buf()
129 }
130}
131
132impl IntoBuf for u8 {
133 type Buf = Option<[u8; 1]>;
134
135 fn into_buf(self) -> Self::Buf {
136 Some([self])
137 }
138}
139
140impl IntoBuf for i8 {
141 type Buf = Option<[u8; 1]>;
142
143 fn into_buf(self) -> Self::Buf {
144 Some([self as u8; 1])
145 }
146}