1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use super::arc::ArcBuffer;
use alloc::{string::String, vec::Vec};
use core::hash::{Hash, Hasher};
#[pen_ffi_macro::any(crate = "crate")]
#[repr(C)]
#[derive(Clone, Debug, Default)]
pub struct ByteString {
buffer: ArcBuffer,
}
impl ByteString {
pub fn as_slice(&self) -> &[u8] {
self.buffer.as_slice()
}
}
impl PartialEq for ByteString {
fn eq(&self, other: &Self) -> bool {
self.as_slice() == other.as_slice()
}
}
impl Eq for ByteString {}
impl Hash for ByteString {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.as_slice().hash(hasher)
}
}
impl From<&[u8]> for ByteString {
fn from(bytes: &[u8]) -> Self {
Self {
buffer: bytes.into(),
}
}
}
impl From<&str> for ByteString {
fn from(string: &str) -> Self {
string.as_bytes().into()
}
}
impl From<String> for ByteString {
fn from(string: String) -> Self {
string.as_str().into()
}
}
impl From<Vec<u8>> for ByteString {
fn from(vec: Vec<u8>) -> Self {
vec.as_slice().into()
}
}