spinoso_string/enc/
impls.rs1use core::ops::{Deref, DerefMut};
2
3use super::EncodedString;
4
5impl Extend<u8> for EncodedString {
6 #[inline]
7 fn extend<I: IntoIterator<Item = u8>>(&mut self, iter: I) {
8 match self {
9 EncodedString::Ascii(inner) => inner.extend(iter),
10 EncodedString::Binary(inner) => inner.extend(iter),
11 EncodedString::Utf8(inner) => inner.extend(iter),
12 }
13 }
14}
15
16impl<'a> Extend<&'a u8> for EncodedString {
17 #[inline]
18 fn extend<I: IntoIterator<Item = &'a u8>>(&mut self, iter: I) {
19 match self {
20 EncodedString::Ascii(inner) => inner.extend(iter),
21 EncodedString::Binary(inner) => inner.extend(iter),
22 EncodedString::Utf8(inner) => inner.extend(iter),
23 }
24 }
25}
26
27impl AsRef<[u8]> for EncodedString {
28 #[inline]
29 fn as_ref(&self) -> &[u8] {
30 match self {
31 EncodedString::Ascii(inner) => inner.as_ref(),
32 EncodedString::Binary(inner) => inner.as_ref(),
33 EncodedString::Utf8(inner) => inner.as_ref(),
34 }
35 }
36}
37
38impl AsMut<[u8]> for EncodedString {
39 #[inline]
40 fn as_mut(&mut self) -> &mut [u8] {
41 match self {
42 EncodedString::Ascii(inner) => inner.as_mut(),
43 EncodedString::Binary(inner) => inner.as_mut(),
44 EncodedString::Utf8(inner) => inner.as_mut(),
45 }
46 }
47}
48
49impl Deref for EncodedString {
50 type Target = [u8];
51
52 #[inline]
53 fn deref(&self) -> &[u8] {
54 match self {
55 EncodedString::Ascii(inner) => inner,
56 EncodedString::Binary(inner) => inner,
57 EncodedString::Utf8(inner) => inner.as_bytes(),
58 }
59 }
60}
61
62impl DerefMut for EncodedString {
63 #[inline]
64 fn deref_mut(&mut self) -> &mut [u8] {
65 match self {
66 EncodedString::Ascii(inner) => &mut *inner,
67 EncodedString::Binary(inner) => &mut *inner,
68 EncodedString::Utf8(inner) => inner.as_bytes_mut(),
69 }
70 }
71}