vortex_io/segments/
mod.rs1mod file;
7mod read;
8mod shared;
9
10use std::fmt;
11use std::fmt::Display;
12use std::ops::Deref;
13use std::sync::Arc;
14
15pub use file::*;
16use futures::future::BoxFuture;
17pub use shared::*;
18use vortex_array::buffer::BufferHandle;
19use vortex_buffer::Alignment;
20use vortex_error::VortexError;
21use vortex_error::VortexResult;
22
23#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
29pub struct SegmentId(u32);
30
31impl From<u32> for SegmentId {
32 fn from(value: u32) -> Self {
33 Self(value)
34 }
35}
36
37impl TryFrom<usize> for SegmentId {
38 type Error = VortexError;
39
40 fn try_from(value: usize) -> Result<Self, Self::Error> {
41 Ok(Self::from(u32::try_from(value)?))
42 }
43}
44
45impl Deref for SegmentId {
46 type Target = u32;
47
48 fn deref(&self) -> &Self::Target {
49 &self.0
50 }
51}
52
53impl Display for SegmentId {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 write!(f, "SegmentId({})", self.0)
56 }
57}
58
59pub type SegmentFuture = BoxFuture<'static, VortexResult<BufferHandle>>;
61
62pub trait SegmentSource: 'static + Send + Sync {
67 fn request(&self, id: SegmentId) -> SegmentFuture;
69}
70
71impl SegmentSource for Arc<dyn SegmentSource> {
72 fn request(&self, id: SegmentId) -> SegmentFuture {
73 self.as_ref().request(id)
74 }
75}
76
77#[derive(Clone, Copy, Debug, PartialEq, Eq)]
79pub struct SegmentLocation {
80 pub offset: u64,
82 pub length: u32,
84 pub alignment: Alignment,
86}