Skip to content

feat: Add Blobs::builder and use it from Blobs::memory and Blobs::persistent #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/net_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,30 @@ impl<S: crate::store::Store> Builder<S> {
}
}

impl Blobs<crate::store::mem::Store> {
/// Create a new memory-backed Blobs protocol handler.
pub fn memory() -> Builder<crate::store::mem::Store> {
impl<S> Blobs<S> {
/// Create a new Blobs protocol handler builder, given a store.
pub fn builder(store: S) -> Builder<S> {
Builder {
store: crate::store::mem::Store::new(),
store,
events: None,
gc_config: None,
}
}
}

impl Blobs<crate::store::mem::Store> {
/// Create a new memory-backed Blobs protocol handler.
pub fn memory() -> Builder<crate::store::mem::Store> {
Self::builder(crate::store::mem::Store::new())
}
}

impl Blobs<crate::store::fs::Store> {
/// Load a persistent Blobs protocol handler from a path.
pub async fn persistent(
path: impl AsRef<std::path::Path>,
) -> anyhow::Result<Builder<crate::store::fs::Store>> {
Ok(Builder {
store: crate::store::fs::Store::load(path).await?,
events: None,
gc_config: None,
})
Ok(Self::builder(crate::store::fs::Store::load(path).await?))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/store/fs/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ pub(super) struct ReadOnlyTables {
pub inline_outboard: redb::ReadOnlyTable<Hash, &'static [u8]>,
}

impl<'txn> ReadOnlyTables {
pub fn new(tx: &'txn redb::ReadTransaction) -> std::result::Result<Self, TableError> {
impl ReadOnlyTables {
pub fn new(tx: &redb::ReadTransaction) -> std::result::Result<Self, TableError> {
Ok(Self {
blobs: tx.open_table(BLOBS_TABLE)?,
tags: tx.open_table(TAGS_TABLE)?,
Expand Down
Loading