mod file;
mod read;
mod shared;
use std::fmt;
use std::fmt::Display;
use std::ops::Deref;
use std::sync::Arc;
pub use file::*;
use futures::future::BoxFuture;
pub use shared::*;
use vortex_array::buffer::BufferHandle;
use vortex_buffer::Alignment;
use vortex_error::VortexError;
use vortex_error::VortexResult;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SegmentId(u32);
impl From<u32> for SegmentId {
fn from(value: u32) -> Self {
Self(value)
}
}
impl TryFrom<usize> for SegmentId {
type Error = VortexError;
fn try_from(value: usize) -> Result<Self, Self::Error> {
Ok(Self::from(u32::try_from(value)?))
}
}
impl Deref for SegmentId {
type Target = u32;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Display for SegmentId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SegmentId({})", self.0)
}
}
pub type SegmentFuture = BoxFuture<'static, VortexResult<BufferHandle>>;
pub trait SegmentSource: 'static + Send + Sync {
fn request(&self, id: SegmentId) -> SegmentFuture;
}
impl SegmentSource for Arc<dyn SegmentSource> {
fn request(&self, id: SegmentId) -> SegmentFuture {
self.as_ref().request(id)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SegmentLocation {
pub offset: u64,
pub length: u32,
pub alignment: Alignment,
}