Skip to content

refactor: hide or remove unused code. #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
//!
//! This API is both for interacting with an in-process store and for interacting
//! with a remote store via rpc calls.
//!
//! The entry point for the api is the [`Store`] struct. There are several ways
//! to obtain a `Store` instance: it is available via [`Deref`](std::ops::Deref)
//! from the different store implementations
//! (e.g. [`MemStore`](crate::store::mem::MemStore)
//! and [`FsStore`](crate::store::fs::FsStore)) as well as on the
//! [`BlobsProtocol`](crate::BlobsProtocol) iroh protocol handler.
//!
//! You can also [`connect`](Store::connect) to a remote store that is listening
//! to rpc requests.
use std::{io, net::SocketAddr, ops::Deref, sync::Arc};

use bao_tree::io::EncodeError;
Expand Down
52 changes: 1 addition & 51 deletions src/hashseq.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Helpers for blobs that contain a sequence of hashes.
use std::{fmt::Debug, io};
use std::fmt::Debug;

use bytes::Bytes;
use iroh_io::{AsyncSliceReader, AsyncSliceReaderExt};

use crate::Hash;

Expand Down Expand Up @@ -51,34 +50,6 @@ impl IntoIterator for HashSeq {
}
}

/// Stream over the hashes in a [`HashSeq`].
///
/// todo: make this wrap a reader instead of a [`HashSeq`].
#[derive(Debug, Clone)]
pub struct HashSeqStream(HashSeq);

impl HashSeqStream {
/// Get the next hash in the sequence.
#[allow(clippy::should_implement_trait, clippy::unused_async)]
pub async fn next(&mut self) -> io::Result<Option<Hash>> {
Ok(self.0.pop_front())
}

/// Skip a number of hashes in the sequence.
#[allow(clippy::unused_async)]
pub async fn skip(&mut self, n: u64) -> io::Result<()> {
let ok = self.0.drop_front(n as usize);
if !ok {
Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"end of sequence",
))
} else {
Ok(())
}
}
}

impl HashSeq {
/// Create a new sequence of hashes.
pub fn new(bytes: Bytes) -> Option<Self> {
Expand All @@ -89,16 +60,6 @@ impl HashSeq {
}
}

fn drop_front(&mut self, n: usize) -> bool {
let start = n * 32;
if start > self.0.len() {
false
} else {
self.0 = self.0.slice(start..);
true
}
}

/// Iterate over the hashes in this sequence.
pub fn iter(&self) -> impl Iterator<Item = Hash> + '_ {
self.0.chunks_exact(32).map(|chunk| {
Expand Down Expand Up @@ -155,14 +116,3 @@ impl Iterator for HashSeqIter {
self.0.pop_front()
}
}

/// Parse a sequence of hashes.
pub async fn parse_hash_seq<'a, R: AsyncSliceReader + 'a>(
mut reader: R,
) -> anyhow::Result<(HashSeqStream, u64)> {
let bytes = reader.read_to_end().await?;
let hashes = HashSeq::try_from(bytes)?;
let num_hashes = hashes.len() as u64;
let stream = HashSeqStream(hashes);
Ok((stream, num_hashes))
}
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ pub use net_protocol::BlobsProtocol;
pub mod protocol;
pub mod provider;
pub mod ticket;
pub mod util;

#[doc(hidden)]
pub mod test;
mod util;

#[cfg(test)]
mod tests;

pub mod test;

pub use protocol::ALPN;
7 changes: 4 additions & 3 deletions src/protocol/range_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
//! collection.
use std::{fmt, sync::OnceLock};

use bao_tree::{ChunkNum, ChunkRanges, ChunkRangesRef};
pub use bao_tree::ChunkRanges;
use bao_tree::{ChunkNum, ChunkRangesRef};
use serde::{Deserialize, Serialize};
use smallvec::{smallvec, SmallVec};

pub use crate::util::ChunkRangesExt;

static CHUNK_RANGES_EMPTY: OnceLock<ChunkRanges> = OnceLock::new();

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

use crate::util::ChunkRangesExt;

#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(from = "wire::RangeSpecSeq", into = "wire::RangeSpecSeq")]
pub struct ChunkRangesSeq(pub(crate) SmallVec<[(u64, ChunkRanges); 2]>);
Expand Down
Loading