Skip to content

Commit ac1e509

Browse files
authored
feat: impl From for api::Store (n0-computer#169)
## Description Currently, when functions want a `iroh_blobs::api::Store`, and you have a `MemStore` or `FsStore`, you have to do `fs_store.as_ref().clone()` to get from the `FsStore` to the `api::Store`. I stumbled a couple of times and had to look that up, it's not very intuitive and hard to find. So to make this easier, this adds `From` impls for `api::Store` for the various stores. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented.
1 parent 5281457 commit ac1e509

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/store/fs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,12 @@ pub struct FsStore {
14461446
db: tokio::sync::mpsc::Sender<InternalCommand>,
14471447
}
14481448

1449+
impl From<FsStore> for Store {
1450+
fn from(value: FsStore) -> Self {
1451+
Store::from_sender(value.sender)
1452+
}
1453+
}
1454+
14491455
impl Deref for FsStore {
14501456
type Target = Store;
14511457

src/store/mem.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ pub struct MemStore {
7474
client: ApiClient,
7575
}
7676

77+
impl From<MemStore> for crate::api::Store {
78+
fn from(value: MemStore) -> Self {
79+
crate::api::Store::from_sender(value.client)
80+
}
81+
}
82+
7783
impl AsRef<crate::api::Store> for MemStore {
7884
fn as_ref(&self) -> &crate::api::Store {
7985
crate::api::Store::ref_from_sender(&self.client)

src/store/readonly_mem.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ impl Deref for ReadonlyMemStore {
5959
}
6060
}
6161

62+
impl From<ReadonlyMemStore> for crate::api::Store {
63+
fn from(value: ReadonlyMemStore) -> Self {
64+
crate::api::Store::from_sender(value.client)
65+
}
66+
}
67+
68+
impl AsRef<crate::api::Store> for ReadonlyMemStore {
69+
fn as_ref(&self) -> &crate::api::Store {
70+
crate::api::Store::ref_from_sender(&self.client)
71+
}
72+
}
73+
6274
struct Actor {
6375
commands: tokio::sync::mpsc::Receiver<proto::Command>,
6476
tasks: JoinSet<()>,

0 commit comments

Comments
 (0)