Skip to content

Commit d5bcbad

Browse files
authored
refactor: hide or remove unused code. (#115)
## Description - Hide the test module from docs (it will be removed/hidden behind afeature flag into a separate crate eventually. - Make util pub(crate) - Remove unused code in the hash_seq module ## Breaking Changes - the util mod is no longer public - the test mod is hidden (will be non-public eventually) - there is a new reexport of ChunkRangeExt in protocol so people can use it ## 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 91459aa commit d5bcbad

File tree

4 files changed

+19
-57
lines changed

4 files changed

+19
-57
lines changed

src/api.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
//!
33
//! This API is both for interacting with an in-process store and for interacting
44
//! with a remote store via rpc calls.
5+
//!
6+
//! The entry point for the api is the [`Store`] struct. There are several ways
7+
//! to obtain a `Store` instance: it is available via [`Deref`](std::ops::Deref)
8+
//! from the different store implementations
9+
//! (e.g. [`MemStore`](crate::store::mem::MemStore)
10+
//! and [`FsStore`](crate::store::fs::FsStore)) as well as on the
11+
//! [`BlobsProtocol`](crate::BlobsProtocol) iroh protocol handler.
12+
//!
13+
//! You can also [`connect`](Store::connect) to a remote store that is listening
14+
//! to rpc requests.
515
use std::{io, net::SocketAddr, ops::Deref, sync::Arc};
616

717
use bao_tree::io::EncodeError;

src/hashseq.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Helpers for blobs that contain a sequence of hashes.
2-
use std::{fmt::Debug, io};
2+
use std::fmt::Debug;
33

44
use bytes::Bytes;
5-
use iroh_io::{AsyncSliceReader, AsyncSliceReaderExt};
65

76
use crate::Hash;
87

@@ -51,34 +50,6 @@ impl IntoIterator for HashSeq {
5150
}
5251
}
5352

54-
/// Stream over the hashes in a [`HashSeq`].
55-
///
56-
/// todo: make this wrap a reader instead of a [`HashSeq`].
57-
#[derive(Debug, Clone)]
58-
pub struct HashSeqStream(HashSeq);
59-
60-
impl HashSeqStream {
61-
/// Get the next hash in the sequence.
62-
#[allow(clippy::should_implement_trait, clippy::unused_async)]
63-
pub async fn next(&mut self) -> io::Result<Option<Hash>> {
64-
Ok(self.0.pop_front())
65-
}
66-
67-
/// Skip a number of hashes in the sequence.
68-
#[allow(clippy::unused_async)]
69-
pub async fn skip(&mut self, n: u64) -> io::Result<()> {
70-
let ok = self.0.drop_front(n as usize);
71-
if !ok {
72-
Err(io::Error::new(
73-
io::ErrorKind::UnexpectedEof,
74-
"end of sequence",
75-
))
76-
} else {
77-
Ok(())
78-
}
79-
}
80-
}
81-
8253
impl HashSeq {
8354
/// Create a new sequence of hashes.
8455
pub fn new(bytes: Bytes) -> Option<Self> {
@@ -89,16 +60,6 @@ impl HashSeq {
8960
}
9061
}
9162

92-
fn drop_front(&mut self, n: usize) -> bool {
93-
let start = n * 32;
94-
if start > self.0.len() {
95-
false
96-
} else {
97-
self.0 = self.0.slice(start..);
98-
true
99-
}
100-
}
101-
10263
/// Iterate over the hashes in this sequence.
10364
pub fn iter(&self) -> impl Iterator<Item = Hash> + '_ {
10465
self.0.chunks_exact(32).map(|chunk| {
@@ -155,14 +116,3 @@ impl Iterator for HashSeqIter {
155116
self.0.pop_front()
156117
}
157118
}
158-
159-
/// Parse a sequence of hashes.
160-
pub async fn parse_hash_seq<'a, R: AsyncSliceReader + 'a>(
161-
mut reader: R,
162-
) -> anyhow::Result<(HashSeqStream, u64)> {
163-
let bytes = reader.read_to_end().await?;
164-
let hashes = HashSeq::try_from(bytes)?;
165-
let num_hashes = hashes.len() as u64;
166-
let stream = HashSeqStream(hashes);
167-
Ok((stream, num_hashes))
168-
}

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ pub use net_protocol::BlobsProtocol;
4040
pub mod protocol;
4141
pub mod provider;
4242
pub mod ticket;
43-
pub mod util;
43+
44+
#[doc(hidden)]
45+
pub mod test;
46+
mod util;
4447

4548
#[cfg(test)]
4649
mod tests;
4750

48-
pub mod test;
49-
5051
pub use protocol::ALPN;

src/protocol/range_spec.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
//! collection.
88
use std::{fmt, sync::OnceLock};
99

10-
use bao_tree::{ChunkNum, ChunkRanges, ChunkRangesRef};
10+
pub use bao_tree::ChunkRanges;
11+
use bao_tree::{ChunkNum, ChunkRangesRef};
1112
use serde::{Deserialize, Serialize};
1213
use smallvec::{smallvec, SmallVec};
1314

15+
pub use crate::util::ChunkRangesExt;
16+
1417
static CHUNK_RANGES_EMPTY: OnceLock<ChunkRanges> = OnceLock::new();
1518

1619
fn chunk_ranges_empty() -> &'static ChunkRanges {
1720
CHUNK_RANGES_EMPTY.get_or_init(ChunkRanges::empty)
1821
}
1922

20-
use crate::util::ChunkRangesExt;
21-
2223
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
2324
#[serde(from = "wire::RangeSpecSeq", into = "wire::RangeSpecSeq")]
2425
pub struct ChunkRangesSeq(pub(crate) SmallVec<[(u64, ChunkRanges); 2]>);

0 commit comments

Comments
 (0)