spinoso_string/enc/binary/
impls.rs1use alloc::borrow::Cow;
2use alloc::string::String;
3use alloc::vec::Vec;
4use core::ops::{Deref, DerefMut};
5
6use scolapasta_strbuf::Buf;
7
8use super::BinaryString;
9
10impl Extend<u8> for BinaryString {
11 #[inline]
12 fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I) {
13 self.inner.extend(iter);
14 }
15}
16
17impl<'a> Extend<&'a u8> for BinaryString {
18 #[inline]
19 fn extend<I: IntoIterator<Item = &'a u8>>(&mut self, iter: I) {
20 self.inner.extend(iter.into_iter().copied());
21 }
22}
23
24impl From<Buf> for BinaryString {
25 #[inline]
26 fn from(content: Buf) -> Self {
27 Self::new(content)
28 }
29}
30
31impl From<Vec<u8>> for BinaryString {
32 #[inline]
33 fn from(content: Vec<u8>) -> Self {
34 let buf = content.into();
35 Self::new(buf)
36 }
37}
38
39impl<const N: usize> From<[u8; N]> for BinaryString {
40 #[inline]
41 fn from(content: [u8; N]) -> Self {
42 let buf = content.to_vec();
43 Self::new(buf.into())
44 }
45}
46
47impl<const N: usize> From<&[u8; N]> for BinaryString {
48 #[inline]
49 fn from(content: &[u8; N]) -> Self {
50 let buf = content.to_vec();
51 Self::new(buf.into())
52 }
53}
54
55impl<'a> From<&'a [u8]> for BinaryString {
56 #[inline]
57 fn from(content: &'a [u8]) -> Self {
58 let buf = content.to_vec();
59 Self::new(buf.into())
60 }
61}
62
63impl<'a> From<&'a mut [u8]> for BinaryString {
64 #[inline]
65 fn from(content: &'a mut [u8]) -> Self {
66 let buf = content.to_vec();
67 Self::new(buf.into())
68 }
69}
70
71impl<'a> From<Cow<'a, [u8]>> for BinaryString {
72 #[inline]
73 fn from(content: Cow<'a, [u8]>) -> Self {
74 let buf = content.into_owned();
75 Self::new(buf.into())
76 }
77}
78
79impl From<String> for BinaryString {
80 #[inline]
81 fn from(s: String) -> Self {
82 let buf = s.into_bytes();
83 Self::new(buf.into())
84 }
85}
86
87impl From<&str> for BinaryString {
88 #[inline]
89 fn from(s: &str) -> Self {
90 let buf = s.as_bytes().to_vec();
91 Self::new(buf.into())
92 }
93}
94
95impl From<BinaryString> for Buf {
96 #[inline]
97 fn from(s: BinaryString) -> Self {
98 s.into_buf()
99 }
100}
101
102impl AsRef<[u8]> for BinaryString {
103 #[inline]
104 fn as_ref(&self) -> &[u8] {
105 self.inner.as_slice()
106 }
107}
108
109impl AsMut<[u8]> for BinaryString {
110 #[inline]
111 fn as_mut(&mut self) -> &mut [u8] {
112 self.inner.as_mut_slice()
113 }
114}
115
116impl Deref for BinaryString {
117 type Target = [u8];
118
119 #[inline]
120 fn deref(&self) -> &[u8] {
121 &self.inner
122 }
123}
124
125impl DerefMut for BinaryString {
126 #[inline]
127 fn deref_mut(&mut self) -> &mut [u8] {
128 &mut self.inner
129 }
130}