embedrs_bytes/buf/
into_buf.rs1use super::{Buf};
2#[allow(unused_imports)]
3use prelude::*;
4
5#[cfg(feature = "std")]
6use std::io;
7
8pub trait IntoBuf {
30 type Buf: Buf;
32
33 fn into_buf(self) -> Self::Buf;
51}
52
53impl<T: Buf> IntoBuf for T {
54 type Buf = Self;
55
56 fn into_buf(self) -> Self {
57 self
58 }
59}
60
61#[cfg(feature = "std")]
62impl<'a> IntoBuf for &'a [u8] {
63 type Buf = io::Cursor<&'a [u8]>;
64
65 fn into_buf(self) -> Self::Buf {
66 io::Cursor::new(self)
67 }
68}
69
70#[cfg(feature = "std")]
71impl<'a> IntoBuf for &'a str {
72 type Buf = io::Cursor<&'a [u8]>;
73
74 fn into_buf(self) -> Self::Buf {
75 self.as_bytes().into_buf()
76 }
77}
78
79#[cfg(feature = "std")]
80impl IntoBuf for Vec<u8> {
81 type Buf = io::Cursor<Vec<u8>>;
82
83 fn into_buf(self) -> Self::Buf {
84 io::Cursor::new(self)
85 }
86}
87
88#[cfg(feature = "std")]
89impl<'a> IntoBuf for &'a Vec<u8> {
90 type Buf = io::Cursor<&'a [u8]>;
91
92 fn into_buf(self) -> Self::Buf {
93 io::Cursor::new(&self[..])
94 }
95}
96
97#[cfg(feature = "std")]
100impl<'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
108#[cfg(feature = "std")]
109impl<'a> IntoBuf for &'a &'static str {
110 type Buf = io::Cursor<&'static [u8]>;
111
112 fn into_buf(self) -> Self::Buf {
113 self.as_bytes().into_buf()
114 }
115}
116
117#[cfg(feature = "std")]
118impl IntoBuf for String {
119 type Buf = io::Cursor<Vec<u8>>;
120
121 fn into_buf(self) -> Self::Buf {
122 self.into_bytes().into_buf()
123 }
124}
125
126#[cfg(feature = "std")]
127impl<'a> IntoBuf for &'a String {
128 type Buf = io::Cursor<&'a [u8]>;
129
130 fn into_buf(self) -> Self::Buf {
131 self.as_bytes().into_buf()
132 }
133}
134
135impl IntoBuf for u8 {
136 type Buf = Option<[u8; 1]>;
137
138 fn into_buf(self) -> Self::Buf {
139 Some([self])
140 }
141}
142
143impl IntoBuf for i8 {
144 type Buf = Option<[u8; 1]>;
145
146 fn into_buf(self) -> Self::Buf {
147 Some([self as u8; 1])
148 }
149}