Dataset length
This commit is contained in:
@@ -40,6 +40,13 @@ pub enum Dataset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Dataset {
|
impl Dataset {
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
match self {
|
||||||
|
Self::Dir(ds) => ds.len(),
|
||||||
|
Self::S3(ds) => ds.len(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get(&self, key: &str) -> Option<Item> {
|
pub async fn get(&self, key: &str) -> Option<Item> {
|
||||||
match self {
|
match self {
|
||||||
Self::Dir(ds) => ds.get(key).await.ok().flatten(),
|
Self::Dir(ds) => ds.get(key).await.ok().flatten(),
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ impl DirDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DataSource for Arc<DirDataSource> {
|
impl DataSource for Arc<DirDataSource> {
|
||||||
|
#[expect(clippy::expect_used)]
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
self.index.get().expect("index should be initialized").len()
|
||||||
|
}
|
||||||
|
|
||||||
#[expect(clippy::expect_used)]
|
#[expect(clippy::expect_used)]
|
||||||
async fn get(&self, key: &str) -> Result<Option<Item>, std::io::Error> {
|
async fn get(&self, key: &str) -> Result<Option<Item>, std::io::Error> {
|
||||||
return Ok(self
|
return Ok(self
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ pub mod misc;
|
|||||||
|
|
||||||
/// A read-only set of [Item]s.
|
/// A read-only set of [Item]s.
|
||||||
pub trait DataSource {
|
pub trait DataSource {
|
||||||
|
/// Get the number of items in this source
|
||||||
|
fn len(&self) -> usize;
|
||||||
|
|
||||||
/// Get an item from this datasource
|
/// Get an item from this datasource
|
||||||
fn get(
|
fn get(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -163,6 +163,11 @@ impl S3DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DataSource for Arc<S3DataSource> {
|
impl DataSource for Arc<S3DataSource> {
|
||||||
|
#[expect(clippy::expect_used)]
|
||||||
|
fn len(&self) -> usize {
|
||||||
|
self.index.get().expect("index should be initialized").len()
|
||||||
|
}
|
||||||
|
|
||||||
#[expect(clippy::expect_used)]
|
#[expect(clippy::expect_used)]
|
||||||
async fn get(&self, key: &str) -> Result<Option<Item>, std::io::Error> {
|
async fn get(&self, key: &str) -> Result<Option<Item>, std::io::Error> {
|
||||||
return Ok(self
|
return Ok(self
|
||||||
|
|||||||
Reference in New Issue
Block a user