1use {
2 crate::xkb::code_slice::CodeSlice,
3 bstr::ByteSlice,
4 std::{
5 fmt::{Debug, Formatter},
6 ops::Deref,
7 sync::Arc,
8 },
9};
10
11#[derive(Clone, Eq, PartialEq)]
12pub(crate) struct Code {
13 code: Arc<Vec<u8>>,
14}
15
16impl Code {
17 pub(crate) fn new(code: &Arc<Vec<u8>>) -> Self {
18 Self { code: code.clone() }
19 }
20
21 pub(crate) fn as_bytes(&self) -> &[u8] {
22 self.code.as_slice()
23 }
24
25 pub(crate) fn to_slice(&self) -> CodeSlice<'_> {
26 CodeSlice::new_ref(self, 0..self.len())
27 }
28}
29
30impl Deref for Code {
31 type Target = [u8];
32
33 fn deref(&self) -> &Self::Target {
34 self.as_bytes()
35 }
36}
37
38impl Debug for Code {
39 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40 Debug::fmt(self.as_bstr(), f)
41 }
42}