Skip to content

Commit b1029e2

Browse files
authored
feat: Enable RPC by default (#73)
## Description Almost the entire friendly API of the crate is only available if the `rpc` feature flag is set. So this enables rpc by default to make the crate easier to use for beginners. I also document feature flags in the module docs (should this instead be in README.md?) so people that need fewer deps know what to do. ## Breaking Changes None ## Notes & open questions Note: there is also a bugfix to the new tags API. The rename fn in the API was not actually using the shiny new atomic rename but just the multi-step rename. If we decide not to enable rpc by default I will move that change into a separate PR. ## Change checklist - [x] Self-review. - [x] 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. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent 6e9f06b commit b1029e2

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ futures-util = "0.3.30"
9696
testdir = "0.9.1"
9797

9898
[features]
99-
default = ["fs-store", "net_protocol"]
99+
default = ["fs-store", "net_protocol", "rpc"]
100100
downloader = ["dep:parking_lot", "tokio-util/time", "dep:hashlink"]
101101
net_protocol = ["downloader", "dep:futures-util"]
102102
fs-store = ["dep:reflink-copy", "redb", "dep:tempfile"]

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
//! The [downloader] module provides a component to download blobs from
2323
//! multiple sources and store them in a store.
2424
//!
25+
//! # Feature flags
26+
//!
27+
//! - rpc: Enable the rpc server and client. Enabled by default.
28+
//! - net_protocol: Enable the network protocol. Enabled by default.
29+
//! - downloader: Enable the downloader. Enabled by default.
30+
//! - fs-store: Enable the filesystem store. Enabled by default.
31+
//!
32+
//! - cli: Enable the cli. Disabled by default.
33+
//! - example-iroh: dependencies for examples in this crate. Disabled by default.
34+
//! - test: test utilities. Disabled by default.
35+
//!
2536
//! [BLAKE3]: https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf
2637
//! [iroh]: https://docs.rs/iroh
2738
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]

src/rpc/client/tags.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
use std::ops::{Bound, RangeBounds};
2424

2525
use anyhow::Result;
26-
use futures_lite::{io, Stream, StreamExt};
26+
use futures_lite::{Stream, StreamExt};
2727
use quic_rpc::{client::BoxedConnector, Connector, RpcClient};
2828
use serde::{Deserialize, Serialize};
2929

3030
use crate::{
3131
rpc::proto::{
32-
tags::{DeleteRequest, ListRequest, SetRequest, SyncMode},
32+
tags::{DeleteRequest, ListRequest, RenameRequest, SetRequest, SyncMode},
3333
RpcService,
3434
},
3535
BlobFormat, Hash, HashAndFormat, Tag,
@@ -235,13 +235,12 @@ where
235235
///
236236
/// If the tag does not exist, this will return an error.
237237
pub async fn rename(&self, from: impl AsRef<[u8]>, to: impl AsRef<[u8]>) -> Result<()> {
238-
let from = from.as_ref();
239-
let to = to.as_ref();
240-
let Some(old) = self.get(from.as_ref()).await? else {
241-
return Err(io::Error::new(io::ErrorKind::NotFound, "Tag not found").into());
242-
};
243-
self.set(to.as_ref(), old.hash_and_format()).await?;
244-
self.delete(from.as_ref()).await?;
238+
self.rpc
239+
.rpc(RenameRequest {
240+
from: Tag::from(from.as_ref()),
241+
to: Tag::from(to.as_ref()),
242+
})
243+
.await??;
245244
Ok(())
246245
}
247246

src/store/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ impl ActorState {
20432043
fn rename_tag(&mut self, tables: &mut Tables, from: Tag, to: Tag) -> ActorResult<()> {
20442044
let value = tables
20452045
.tags
2046-
.get(from)?
2046+
.remove(from)?
20472047
.ok_or_else(|| {
20482048
ActorError::Io(io::Error::new(io::ErrorKind::NotFound, "tag not found"))
20492049
})?

0 commit comments

Comments
 (0)