unity_asset_binary/
shared_bytes.rs

1use std::sync::Arc;
2
3#[derive(Debug, Clone)]
4pub enum SharedBytes {
5    Arc(Arc<[u8]>),
6    #[cfg(feature = "mmap")]
7    Mmap(Arc<memmap2::Mmap>),
8}
9
10impl SharedBytes {
11    pub fn from_vec(data: Vec<u8>) -> Self {
12        Self::Arc(data.into())
13    }
14
15    pub fn from_arc(data: Arc<[u8]>) -> Self {
16        Self::Arc(data)
17    }
18
19    pub fn as_bytes(&self) -> &[u8] {
20        match self {
21            SharedBytes::Arc(v) => v.as_ref(),
22            #[cfg(feature = "mmap")]
23            SharedBytes::Mmap(v) => v.as_ref(),
24        }
25    }
26
27    pub fn len(&self) -> usize {
28        self.as_bytes().len()
29    }
30
31    pub fn is_empty(&self) -> bool {
32        self.len() == 0
33    }
34
35    pub fn ptr_usize(&self) -> usize {
36        self.as_bytes().as_ptr() as usize
37    }
38}