Skip to content

Commit 83c9dcb

Browse files
authored
feat: varint feature flag (#54)
* iroh-blobs uses the varint utils. Currently they are behind the `rpc` feature. However iroh-blobs would use those even when the quinn rpc is disabled. So I added a feature flag for this. Maybe the better thing would be to move those out into a varint crate? Dunno. But this is fine too. * Added a `RequestError::Unreachable` variant if `rpc` feature is disabled. `Snafu` chokes on empty enums somehow. This was the quick fix to have `iroh_blobs` build without irpc's `rpc` feature. Not sure if there is a better way, would need to investigate what exactly snafu does.
1 parent cd72805 commit 83c9dcb

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ quinn_endpoint_setup = ["rpc", "dep:rustls", "dep:rcgen", "dep:anyhow", "dep:fut
7171
spans = ["dep:tracing"]
7272
stream = ["dep:futures-util"]
7373
derive = ["dep:irpc-derive"]
74+
varint-util = ["dep:postcard", "dep:smallvec", "tokio/io-util"]
7475
default = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"]
7576

7677
[[example]]

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ use crate::channel::SendError;
309309

310310
#[cfg(test)]
311311
mod tests;
312-
#[cfg(feature = "rpc")]
313-
#[cfg_attr(quicrpc_docsrs, doc(cfg(feature = "rpc")))]
314312
pub mod util;
315-
#[cfg(not(feature = "rpc"))]
316-
mod util;
317313

318314
mod sealed {
319315
pub trait Sealed {}
@@ -1704,6 +1700,10 @@ pub enum RequestError {
17041700
#[cfg_attr(quicrpc_docsrs, doc(cfg(feature = "rpc")))]
17051701
#[error("error opening stream: {0}")]
17061702
Other(#[from] anyhow::Error),
1703+
1704+
#[cfg(not(feature = "rpc"))]
1705+
#[error("(Without the rpc feature, requests cannot fail")]
1706+
Unreachable,
17071707
}
17081708

17091709
/// Error type that subsumes all possible errors in this crate, for convenience.
@@ -1747,6 +1747,8 @@ impl From<RequestError> for io::Error {
17471747
RequestError::Connection(e) => e.into(),
17481748
#[cfg(feature = "rpc")]
17491749
RequestError::Other(e) => io::Error::other(e),
1750+
#[cfg(not(feature = "rpc"))]
1751+
RequestError::Unreachable => unreachable!(),
17501752
}
17511753
}
17521754
}

src/util.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ mod quinn_setup_utils {
174174
#[cfg_attr(quicrpc_docsrs, doc(cfg(feature = "quinn_endpoint_setup")))]
175175
pub use quinn_setup_utils::*;
176176

177-
#[cfg(feature = "rpc")]
177+
#[cfg(any(feature = "rpc", feature = "varint-util"))]
178+
#[cfg_attr(
179+
quicrpc_docsrs,
180+
doc(cfg(any(feature = "rpc", feature = "varint-util")))
181+
)]
178182
mod varint_util {
179183
use std::{
180184
future::Future,
@@ -382,7 +386,12 @@ mod varint_util {
382386
}
383387
}
384388
}
385-
#[cfg(feature = "rpc")]
389+
390+
#[cfg(any(feature = "rpc", feature = "varint-util"))]
391+
#[cfg_attr(
392+
quicrpc_docsrs,
393+
doc(cfg(any(feature = "rpc", feature = "varint-util")))
394+
)]
386395
pub use varint_util::{AsyncReadVarintExt, AsyncWriteVarintExt, WriteVarintExt};
387396

388397
mod fuse_wrapper {

0 commit comments

Comments
 (0)