Skip to content

Commit d87f671

Browse files
authored
Merge pull request #19 from n0-computer/generic-builder
feat: Add Blobs::builder and use it from Blobs::memory and Blobs::persistent
2 parents 25525a8 + 93d0db2 commit d87f671

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/net_protocol.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -153,27 +153,30 @@ impl<S: crate::store::Store> Builder<S> {
153153
}
154154
}
155155

156-
impl Blobs<crate::store::mem::Store> {
157-
/// Create a new memory-backed Blobs protocol handler.
158-
pub fn memory() -> Builder<crate::store::mem::Store> {
156+
impl<S> Blobs<S> {
157+
/// Create a new Blobs protocol handler builder, given a store.
158+
pub fn builder(store: S) -> Builder<S> {
159159
Builder {
160-
store: crate::store::mem::Store::new(),
160+
store,
161161
events: None,
162162
gc_config: None,
163163
}
164164
}
165165
}
166166

167+
impl Blobs<crate::store::mem::Store> {
168+
/// Create a new memory-backed Blobs protocol handler.
169+
pub fn memory() -> Builder<crate::store::mem::Store> {
170+
Self::builder(crate::store::mem::Store::new())
171+
}
172+
}
173+
167174
impl Blobs<crate::store::fs::Store> {
168175
/// Load a persistent Blobs protocol handler from a path.
169176
pub async fn persistent(
170177
path: impl AsRef<std::path::Path>,
171178
) -> anyhow::Result<Builder<crate::store::fs::Store>> {
172-
Ok(Builder {
173-
store: crate::store::fs::Store::load(path).await?,
174-
events: None,
175-
gc_config: None,
176-
})
179+
Ok(Self::builder(crate::store::fs::Store::load(path).await?))
177180
}
178181
}
179182

src/store/fs/tables.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ pub(super) struct ReadOnlyTables {
8383
pub inline_outboard: redb::ReadOnlyTable<Hash, &'static [u8]>,
8484
}
8585

86-
impl<'txn> ReadOnlyTables {
87-
pub fn new(tx: &'txn redb::ReadTransaction) -> std::result::Result<Self, TableError> {
86+
impl ReadOnlyTables {
87+
pub fn new(tx: &redb::ReadTransaction) -> std::result::Result<Self, TableError> {
8888
Ok(Self {
8989
blobs: tx.open_table(BLOBS_TABLE)?,
9090
tags: tx.open_table(TAGS_TABLE)?,

0 commit comments

Comments
 (0)