1use crate::ion_data::{IonEq, IonOrd};
2use std::cmp::Ordering;
3
4#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
22pub struct Bytes {
23 data: Vec<u8>,
24}
25
26impl IonEq for Bytes {
27 fn ion_eq(&self, other: &Self) -> bool {
28 self == other
29 }
30}
31
32impl IonOrd for Bytes {
33 fn ion_cmp(&self, other: &Self) -> Ordering {
34 self.cmp(other)
35 }
36}
37
38impl PartialEq<[u8]> for Bytes {
39 fn eq(&self, other: &[u8]) -> bool {
40 self.as_ref().eq(other)
41 }
42}
43
44impl From<Vec<u8>> for Bytes {
45 fn from(data: Vec<u8>) -> Self {
46 Bytes { data }
47 }
48}
49
50impl From<&[u8]> for Bytes {
51 fn from(data: &[u8]) -> Self {
52 Bytes {
53 data: data.to_vec(),
54 }
55 }
56}
57
58impl<const N: usize> From<&[u8; N]> for Bytes {
59 fn from(data: &[u8; N]) -> Self {
60 Bytes {
61 data: data.to_vec(),
62 }
63 }
64}
65
66impl From<&str> for Bytes {
67 fn from(text: &str) -> Self {
68 Bytes {
69 data: text.as_bytes().into(),
70 }
71 }
72}
73
74impl AsRef<[u8]> for Bytes {
75 fn as_ref(&self) -> &[u8] {
76 &self.data
77 }
78}