lsm_tree/slice/slice_default/
mod.rs1use byteview::ByteView;
6
7pub use byteview::Builder;
8
9#[derive(Debug, Clone, Eq, Hash, Ord)]
13pub struct Slice(pub(super) ByteView);
14
15impl Slice {
16 #[must_use]
18 pub fn new(bytes: &[u8]) -> Self {
19 Self(bytes.into())
20 }
21
22 #[doc(hidden)]
23 pub fn empty() -> Self {
24 Self(ByteView::new(&[]))
25 }
26
27 #[doc(hidden)]
28 pub unsafe fn builder_unzeroed(len: usize) -> Builder {
29 ByteView::builder_unzeroed(len)
30 }
31
32 pub(crate) fn slice(&self, range: impl std::ops::RangeBounds<usize>) -> Self {
33 Self(self.0.slice(range))
34 }
35
36 pub(crate) fn fused(left: &[u8], right: &[u8]) -> Self {
37 Self(ByteView::fused(left, right))
38 }
39
40 #[doc(hidden)]
41 pub fn from_reader<R: std::io::Read>(reader: &mut R, len: usize) -> std::io::Result<Self> {
42 ByteView::from_reader(reader, len).map(Self)
43 }
44}
45
46impl From<Vec<u8>> for Slice {
48 fn from(value: Vec<u8>) -> Self {
49 Self(ByteView::from(value))
50 }
51}
52
53impl From<String> for Slice {
55 fn from(value: String) -> Self {
56 Self(ByteView::from(value.into_bytes()))
57 }
58}
59
60impl From<ByteView> for Slice {
61 fn from(value: ByteView) -> Self {
62 Self(value)
63 }
64}
65
66impl From<Slice> for ByteView {
67 fn from(value: Slice) -> Self {
68 value.0
69 }
70}