linera_wasmer/
into_bytes.rs

1use bytes::Bytes;
2use std::borrow::Cow;
3
4/// Convert binary data into [`bytes::Bytes`].
5pub trait IntoBytes {
6    /// Convert binary data into [`bytes::Bytes`].
7    fn into_bytes(self) -> Bytes;
8}
9
10impl IntoBytes for Bytes {
11    fn into_bytes(self) -> Bytes {
12        self
13    }
14}
15
16impl IntoBytes for Vec<u8> {
17    fn into_bytes(self) -> Bytes {
18        Bytes::from(self)
19    }
20}
21
22impl IntoBytes for &Vec<u8> {
23    fn into_bytes(self) -> Bytes {
24        Bytes::from(self.clone())
25    }
26}
27
28impl IntoBytes for &[u8] {
29    fn into_bytes(self) -> Bytes {
30        Bytes::from(self.to_vec())
31    }
32}
33
34impl<const N: usize> IntoBytes for &[u8; N] {
35    fn into_bytes(self) -> Bytes {
36        Bytes::from(self.to_vec())
37    }
38}
39
40impl IntoBytes for &str {
41    fn into_bytes(self) -> Bytes {
42        Bytes::from(self.as_bytes().to_vec())
43    }
44}
45
46impl IntoBytes for Cow<'_, [u8]> {
47    fn into_bytes(self) -> Bytes {
48        Bytes::from(self.to_vec())
49    }
50}