diff --git a/iroh-bytes/src/protocol/range_spec.rs b/iroh-bytes/src/protocol/range_spec.rs index f96b9f0cec..566cddb6ec 100644 --- a/iroh-bytes/src/protocol/range_spec.rs +++ b/iroh-bytes/src/protocol/range_spec.rs @@ -230,7 +230,7 @@ impl RangeSpecSeq { /// Thus the first call to `.next()` returns the range spec for the first blob, the next /// call returns the range spec of the second blob, etc. pub fn iter(&self) -> RequestRangeSpecIter<'_> { - let before_first = self.0.get(0).map(|(c, _)| *c).unwrap_or_default(); + let before_first = self.0.first().map(|(c, _)| *c).unwrap_or_default(); RequestRangeSpecIter { current: &EMPTY_RANGE_SPEC, count: before_first, @@ -269,7 +269,7 @@ pub struct RequestRangeSpecIter<'a> { impl<'a> RequestRangeSpecIter<'a> { pub fn new(ranges: &'a [(u64, RangeSpec)]) -> Self { - let before_first = ranges.get(0).map(|(c, _)| *c).unwrap_or_default(); + let before_first = ranges.first().map(|(c, _)| *c).unwrap_or_default(); RequestRangeSpecIter { current: &EMPTY_RANGE_SPEC, count: before_first, @@ -298,7 +298,7 @@ impl<'a> Iterator for RequestRangeSpecIter<'a> { } else if let Some(((_, new), rest)) = self.remaining.split_first() { // get next current value, new count, and set remaining self.current = new; - self.count = rest.get(0).map(|(c, _)| *c).unwrap_or_default(); + self.count = rest.first().map(|(c, _)| *c).unwrap_or_default(); self.remaining = rest; continue; } else { diff --git a/iroh-sync/src/lib.rs b/iroh-sync/src/lib.rs index 8f709d49dc..137a066308 100644 --- a/iroh-sync/src/lib.rs +++ b/iroh-sync/src/lib.rs @@ -40,6 +40,6 @@ mod ranger; pub mod store; pub mod sync; -pub use heads::*; -pub use keys::*; -pub use sync::*; +pub use self::heads::*; +pub use self::keys::*; +pub use self::sync::*; diff --git a/iroh-sync/src/net/codec.rs b/iroh-sync/src/net/codec.rs index 8fae754079..58728e96e7 100644 --- a/iroh-sync/src/net/codec.rs +++ b/iroh-sync/src/net/codec.rs @@ -295,9 +295,8 @@ impl BobState { mod tests { use crate::{ actor::OpenOpts, + keys::{AuthorId, Namespace}, store::{self, GetFilter, Store}, - sync::Namespace, - AuthorId, }; use anyhow::Result; use iroh_bytes::Hash; diff --git a/iroh-sync/src/store.rs b/iroh-sync/src/store.rs index 7d7793d456..ec993300c4 100644 --- a/iroh-sync/src/store.rs +++ b/iroh-sync/src/store.rs @@ -9,8 +9,9 @@ use serde::{Deserialize, Serialize}; use crate::{ heads::AuthorHeads, + keys::{Author, Namespace}, ranger, - sync::{Author, Namespace, Replica, SignedEntry}, + sync::{Replica, SignedEntry}, AuthorId, NamespaceId, PeerIdBytes, }; diff --git a/iroh-sync/src/store/fs.rs b/iroh-sync/src/store/fs.rs index 9f4a15709d..d51814c0b0 100644 --- a/iroh-sync/src/store/fs.rs +++ b/iroh-sync/src/store/fs.rs @@ -19,11 +19,10 @@ use redb::{ }; use crate::{ + keys::{Author, Namespace}, ranger::{Fingerprint, Range, RangeEntry}, store::Store as _, - sync::{ - Author, Entry, EntrySignature, Namespace, Record, RecordIdentifier, Replica, SignedEntry, - }, + sync::{Entry, EntrySignature, Record, RecordIdentifier, Replica, SignedEntry}, AuthorId, NamespaceId, PeerIdBytes, }; diff --git a/iroh-sync/src/store/memory.rs b/iroh-sync/src/store/memory.rs index cff58e7e8c..405a412d21 100644 --- a/iroh-sync/src/store/memory.rs +++ b/iroh-sync/src/store/memory.rs @@ -12,8 +12,9 @@ use iroh_bytes::Hash; use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard}; use crate::{ + keys::{Author, Namespace}, ranger::{Fingerprint, Range, RangeEntry}, - sync::{Author, Namespace, RecordIdentifier, Replica, SignedEntry}, + sync::{RecordIdentifier, Replica, SignedEntry}, AuthorId, NamespaceId, PeerIdBytes, Record, }; diff --git a/iroh-sync/src/sync.rs b/iroh-sync/src/sync.rs index f31aa60406..a4ebad7ac4 100644 --- a/iroh-sync/src/sync.rs +++ b/iroh-sync/src/sync.rs @@ -13,8 +13,6 @@ use std::{ time::{Duration, SystemTime}, }; -#[cfg(feature = "metrics")] -use crate::metrics::Metrics; use bytes::{Bytes, BytesMut}; use derive_more::Deref; #[cfg(feature = "metrics")] @@ -25,8 +23,10 @@ use iroh_bytes::Hash; use serde::{Deserialize, Serialize}; pub use crate::heads::AuthorHeads; -pub use crate::keys::*; +#[cfg(feature = "metrics")] +use crate::metrics::Metrics; use crate::{ + keys::{base32, Author, AuthorId, AuthorPublicKey, Namespace, NamespaceId, NamespacePublicKey}, ranger::{self, Fingerprint, InsertOutcome, Peer, RangeEntry, RangeKey, RangeValue}, store::{self, PublicKeyStore}, }; diff --git a/iroh-test/src/hexdump.rs b/iroh-test/src/hexdump.rs index 9a935b1b2f..4c5e06727d 100644 --- a/iroh-test/src/hexdump.rs +++ b/iroh-test/src/hexdump.rs @@ -65,6 +65,33 @@ pub fn print_hexdump(bytes: impl AsRef<[u8]>, line_lengths: impl AsRef<[usize]>) output } +/// This is a macro to assert that two byte slices are equal. +/// +/// It is like assert_eq!, but it will print a nicely formatted hexdump of the +/// two slices if they are not equal. This makes it much easier to track down +/// a difference in a large byte slice. +#[macro_export] +macro_rules! assert_eq_hex { + ($a:expr, $b:expr) => { + assert_eq_hex!($a, $b, []) + }; + ($a:expr, $b:expr, $hint:expr) => { + let a = $a; + let b = $b; + let hint = $hint; + let ar: &[u8] = a.as_ref(); + let br: &[u8] = b.as_ref(); + let hintr: &[usize] = hint.as_ref(); + if ar != br { + panic!( + "assertion failed: `(left == right)`\nleft:\n{}\nright:\n{}\n", + ::iroh_test::hexdump::print_hexdump(ar, hintr), + ::iroh_test::hexdump::print_hexdump(br, hintr), + ) + } + }; +} + #[cfg(test)] mod tests { use super::{parse_hexdump, print_hexdump}; @@ -151,30 +178,3 @@ mod tests { assert_eq!(output, "01\n\n\n02 03\n04 05\n06 07\n08\n"); } } - -/// This is a macro to assert that two byte slices are equal. -/// -/// It is like assert_eq!, but it will print a nicely formatted hexdump of the -/// two slices if they are not equal. This makes it much easier to track down -/// a difference in a large byte slice. -#[macro_export] -macro_rules! assert_eq_hex { - ($a:expr, $b:expr) => { - assert_eq_hex!($a, $b, []) - }; - ($a:expr, $b:expr, $hint:expr) => { - let a = $a; - let b = $b; - let hint = $hint; - let ar: &[u8] = a.as_ref(); - let br: &[u8] = b.as_ref(); - let hintr: &[usize] = hint.as_ref(); - if ar != br { - panic!( - "assertion failed: `(left == right)`\nleft:\n{}\nright:\n{}\n", - ::iroh_test::hexdump::print_hexdump(ar, hintr), - ::iroh_test::hexdump::print_hexdump(br, hintr), - ) - } - }; -} diff --git a/iroh/examples/dump-blob-stream.rs b/iroh/examples/dump-blob-stream.rs index f51112dcfb..05ede6e538 100644 --- a/iroh/examples/dump-blob-stream.rs +++ b/iroh/examples/dump-blob-stream.rs @@ -115,7 +115,7 @@ fn stream_children(initial: AtInitial) -> impl Stream> let links: Box<[iroh_bytes::Hash]> = postcard::from_bytes(&links_bytes) .map_err(|_| io::Error::new(io::ErrorKind::Other, "failed to parse links"))?; let meta_link = *links - .get(0) + .first() .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "missing meta link"))?; let (meta_end, _meta_bytes) = at_meta.next(meta_link).concatenate_into_vec().await?; let mut curr = meta_end.next(); diff --git a/iroh/src/rpc_protocol.rs b/iroh/src/rpc_protocol.rs index 353731ffa7..7bd4093ca1 100644 --- a/iroh/src/rpc_protocol.rs +++ b/iroh/src/rpc_protocol.rs @@ -22,8 +22,8 @@ use iroh_net::{ use iroh_sync::{ actor::OpenState, store::GetFilter, - sync::{NamespaceId, SignedEntry}, - AuthorId, + sync::SignedEntry, + {AuthorId, NamespaceId}, }; use quic_rpc::{ message::{BidiStreaming, BidiStreamingMsg, Msg, RpcMsg, ServerStreaming, ServerStreamingMsg}, diff --git a/iroh/src/sync_engine.rs b/iroh/src/sync_engine.rs index 1ba94afb54..bd6e620ad5 100644 --- a/iroh/src/sync_engine.rs +++ b/iroh/src/sync_engine.rs @@ -13,7 +13,7 @@ use iroh_bytes::{store::EntryStatus, util::runtime::Handle, Hash}; use iroh_gossip::net::Gossip; use iroh_net::{key::PublicKey, MagicEndpoint, PeerAddr}; use iroh_sync::{ - actor::SyncHandle, sync::NamespaceId, ContentStatus, ContentStatusCallback, Entry, InsertOrigin, + actor::SyncHandle, ContentStatus, ContentStatusCallback, Entry, InsertOrigin, NamespaceId, }; use serde::{Deserialize, Serialize}; use tokio::sync::{mpsc, oneshot}; diff --git a/iroh/src/sync_engine/rpc.rs b/iroh/src/sync_engine/rpc.rs index 78e445b349..e7e647cf08 100644 --- a/iroh/src/sync_engine/rpc.rs +++ b/iroh/src/sync_engine/rpc.rs @@ -3,7 +3,7 @@ use anyhow::anyhow; use futures::Stream; use iroh_bytes::{store::Store as BaoStore, util::BlobFormat}; -use iroh_sync::{sync::Namespace, Author}; +use iroh_sync::{Author, Namespace}; use tokio_stream::StreamExt; use crate::{