vortex_layout/segments/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4mod events;
5mod sink;
6mod source;
7
8#[cfg(any(test, feature = "test-harness"))]
9mod test;
10
11use std::fmt::Display;
12use std::ops::Deref;
13
14pub use events::*;
15pub use sink::*;
16pub use source::*;
17#[cfg(any(test, feature = "test-harness"))]
18pub use test::*;
19use vortex_error::VortexError;
20
21/// The identifier for a single segment.
22// TODO(ngates): should this be a `[u8]` instead? Allowing for arbitrary segment identifiers?
23#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
24pub struct SegmentId(u32);
25
26impl From<u32> for SegmentId {
27    fn from(value: u32) -> Self {
28        Self(value)
29    }
30}
31
32impl TryFrom<usize> for SegmentId {
33    type Error = VortexError;
34
35    fn try_from(value: usize) -> Result<Self, Self::Error> {
36        Ok(Self::from(u32::try_from(value)?))
37    }
38}
39
40impl Deref for SegmentId {
41    type Target = u32;
42
43    fn deref(&self) -> &Self::Target {
44        &self.0
45    }
46}
47
48impl Display for SegmentId {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        write!(f, "SegmentId({})", self.0)
51    }
52}