pub trait Dataset {
type Sample;
type Error;
// Required methods
fn len(&self) -> usize;
fn get(&self, index: usize) -> Result<Self::Sample, Self::Error>;
// Provided methods
fn get_batch(
&self,
indices: &[usize],
) -> Result<Vec<Self::Sample>, Self::Error> { ... }
fn get_batch_with_context(
&self,
indices: &[usize],
context: &WorkerContext,
) -> Result<Vec<Self::Sample>, Self::Error> { ... }
fn is_empty(&self) -> bool { ... }
fn samples(&self) -> DatasetSamples<'_, Self> ⓘ
where Self: Sized { ... }
}Expand description
A finite, indexable collection of samples.
Implementations return owned samples so loaders can move them into batches
without cloning. Dataset-specific failures remain in Dataset::Error.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn get_batch(&self, indices: &[usize]) -> Result<Vec<Self::Sample>, Self::Error>
fn get_batch(&self, indices: &[usize]) -> Result<Vec<Self::Sample>, Self::Error>
Loads samples for one index batch.
The default calls Dataset::get once per index. Overrides must
return exactly one sample per supplied index and preserve index order.
Sourcefn get_batch_with_context(
&self,
indices: &[usize],
context: &WorkerContext,
) -> Result<Vec<Self::Sample>, Self::Error>
fn get_batch_with_context( &self, indices: &[usize], context: &WorkerContext, ) -> Result<Vec<Self::Sample>, Self::Error>
Loads one index batch with cooperative worker lifecycle context.
The source-compatible default ignores context and delegates to
Dataset::get_batch exactly once. Context-aware datasets may
override this hook to honor cancellation and deadlines between bounded
operations. Rust cannot force-cancel an arbitrary blocking native call.
Sourcefn samples(&self) -> DatasetSamples<'_, Self> ⓘwhere
Self: Sized,
fn samples(&self) -> DatasetSamples<'_, Self> ⓘwhere
Self: Sized,
Iterates over every sample in index order.
The iterator borrows the dataset and calls Dataset::get lazily.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".