Skip to content

Commit

Permalink
refactor: more privatization
Browse files Browse the repository at this point in the history
  • Loading branch information
rklaehn committed Feb 6, 2023
1 parent d63fea1 commit 5994474
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ use crate::util::{self, Hash};
const MAX_CONNECTIONS: u64 = 1024;
const MAX_STREAMS: u64 = 10;

pub type Database = Arc<HashMap<Hash, BlobOrCollection>>;
#[derive(Debug, Clone)]
pub struct Database(Arc<HashMap<Hash, BlobOrCollection>>);

impl Database {
fn get(&self, key: &Hash) -> Option<&BlobOrCollection> {
self.0.get(key)
}
}

/// Builder for the [`Provider`].
///
Expand All @@ -44,7 +51,7 @@ pub struct Builder {
}

#[derive(Debug)]
pub enum BlobOrCollection {
pub(crate) enum BlobOrCollection {
Blob(Data),
Collection((Bytes, Bytes)),
}
Expand Down Expand Up @@ -408,7 +415,7 @@ async fn send_blob<W: AsyncWrite + Unpin + Send + 'static>(
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Data {
pub(crate) struct Data {
/// Outboard data from bao.
outboard: Bytes,
/// Path to the original data, which must not change while in use.
Expand Down Expand Up @@ -560,7 +567,7 @@ pub async fn create_collection(data_sources: Vec<DataSource>) -> Result<(Databas
BlobOrCollection::Collection((Bytes::from(outboard), Bytes::from(data.to_vec()))),
);

Ok((Arc::new(db), hash))
Ok((Database(Arc::new(db)), hash))
}

async fn write_response<W: AsyncWrite + Unpin>(
Expand Down

0 comments on commit 5994474

Please sign in to comment.