ai_dataloader/indexable/dataset/
get_sample.rs

1use std::collections::VecDeque;
2
3/// Return a sample from the dataset at a given index.
4pub trait GetSample {
5    /// Type of one sample of the dataset.
6    type Sample: Sized;
7    /// Return the dataset sample corresponding to the index.
8    fn get_sample(&self, index: usize) -> Self::Sample;
9}
10
11impl<T: Clone> GetSample for Vec<T> {
12    type Sample = T;
13    fn get_sample(&self, index: usize) -> Self::Sample {
14        self[index].clone()
15    }
16}
17
18impl<T: Clone> GetSample for VecDeque<T> {
19    type Sample = T;
20    fn get_sample(&self, index: usize) -> Self::Sample {
21        self[index].clone()
22    }
23}
24
25// TODO: `GetSample` for Array?