Skip to content

Commit 5abe918

Browse files
committed
chore: clippy fixes
1 parent 37bd4a2 commit 5abe918

6 files changed

Lines changed: 65 additions & 43 deletions

File tree

src/heads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl AuthorHeads {
6161
}
6262

6363
/// Create an iterator over the entries in this state.
64-
pub fn iter(&self) -> std::collections::btree_map::Iter<AuthorId, Timestamp> {
64+
pub fn iter(&self) -> std::collections::btree_map::Iter<'_, AuthorId, Timestamp> {
6565
self.heads.iter()
6666
}
6767

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod ticket;
4242

4343
pub mod engine;
4444

45-
mod actor;
45+
pub mod actor;
4646
pub mod api;
4747
pub mod store;
4848
pub mod sync;

src/ranger.rs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implementation of Set Reconcilliation based on
22
//! "Range-Based Set Reconciliation" by Aljoscha Meyer.
33
4-
use std::{cmp::Ordering, fmt::Debug, pin::Pin};
4+
use std::{fmt::Debug, pin::Pin};
55

66
use n0_future::StreamExt;
77
use serde::{Deserialize, Serialize};
@@ -62,36 +62,33 @@ pub trait RangeValue: Sized + Debug + Ord + PartialEq + Clone + 'static {}
6262
///
6363
/// This means that ranges are "wrap around" conceptually.
6464
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]
65-
pub struct Range<K> {
65+
pub(crate) struct Range<K> {
6666
x: K,
6767
y: K,
6868
}
6969

7070
impl<K> Range<K> {
71-
pub fn x(&self) -> &K {
71+
pub(crate) fn x(&self) -> &K {
7272
&self.x
7373
}
7474

75-
pub fn y(&self) -> &K {
75+
pub(crate) fn y(&self) -> &K {
7676
&self.y
7777
}
7878

79-
pub fn new(x: K, y: K) -> Self {
80-
Range { x, y }
81-
}
82-
83-
pub fn map<X>(self, f: impl FnOnce(K, K) -> (X, X)) -> Range<X> {
84-
let (x, y) = f(self.x, self.y);
79+
pub(crate) fn new(x: K, y: K) -> Self {
8580
Range { x, y }
8681
}
8782
}
8883

8984
impl<K: Ord> Range<K> {
90-
pub fn is_all(&self) -> bool {
85+
pub(crate) fn is_all(&self) -> bool {
9186
self.x() == self.y()
9287
}
9388

94-
pub fn contains(&self, t: &K) -> bool {
89+
#[cfg(test)]
90+
pub(crate) fn contains(&self, t: &K) -> bool {
91+
use std::cmp::Ordering;
9592
match self.x().cmp(self.y()) {
9693
Ordering::Equal => true,
9794
Ordering::Less => self.x() <= t && t < self.y(),
@@ -117,13 +114,9 @@ impl Debug for Fingerprint {
117114

118115
impl Fingerprint {
119116
/// The fingerprint of the empty set
120-
pub fn empty() -> Self {
117+
pub(crate) fn empty() -> Self {
121118
Fingerprint(*blake3::hash(&[]).as_bytes())
122119
}
123-
124-
pub fn new<T: RangeEntry>(val: T) -> Self {
125-
val.as_fingerprint()
126-
}
127120
}
128121

129122
impl std::ops::BitXorAssign for Fingerprint {
@@ -140,9 +133,9 @@ pub struct RangeFingerprint<K> {
140133
serialize = "Range<K>: Serialize",
141134
deserialize = "Range<K>: Deserialize<'de>"
142135
))]
143-
pub range: Range<K>,
136+
pub(crate) range: Range<K>,
144137
/// The fingerprint of `range`.
145-
pub fingerprint: Fingerprint,
138+
pub(crate) fingerprint: Fingerprint,
146139
}
147140

148141
/// Transfers items inside a range to the other participant.
@@ -153,12 +146,12 @@ pub struct RangeItem<E: RangeEntry> {
153146
serialize = "Range<E::Key>: Serialize",
154147
deserialize = "Range<E::Key>: Deserialize<'de>"
155148
))]
156-
pub range: Range<E::Key>,
149+
pub(crate) range: Range<E::Key>,
157150
#[serde(bound(serialize = "E: Serialize", deserialize = "E: Deserialize<'de>"))]
158-
pub values: Vec<(E, ContentStatus)>,
151+
pub(crate) values: Vec<(E, ContentStatus)>,
159152
/// If false, requests to send local items in the range.
160153
/// Otherwise not.
161-
pub have_local: bool,
154+
pub(crate) have_local: bool,
162155
}
163156

164157
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -176,15 +169,17 @@ pub enum MessagePart<E: RangeEntry> {
176169
}
177170

178171
impl<E: RangeEntry> MessagePart<E> {
179-
pub fn is_range_fingerprint(&self) -> bool {
172+
#[cfg(test)]
173+
pub(crate) fn is_range_fingerprint(&self) -> bool {
180174
matches!(self, MessagePart::RangeFingerprint(_))
181175
}
182176

183-
pub fn is_range_item(&self) -> bool {
177+
#[cfg(test)]
178+
pub(crate) fn is_range_item(&self) -> bool {
184179
matches!(self, MessagePart::RangeItem(_))
185180
}
186181

187-
pub fn values(&self) -> Option<&[(E, ContentStatus)]> {
182+
pub(crate) fn values(&self) -> Option<&[(E, ContentStatus)]> {
188183
match self {
189184
MessagePart::RangeFingerprint(_) => None,
190185
MessagePart::RangeItem(RangeItem { values, .. }) => Some(values),
@@ -211,15 +206,15 @@ impl<E: RangeEntry> Message<E> {
211206
Ok(Message { parts: vec![part] })
212207
}
213208

214-
pub fn parts(&self) -> &[MessagePart<E>] {
209+
pub(crate) fn parts(&self) -> &[MessagePart<E>] {
215210
&self.parts
216211
}
217212

218-
pub fn values(&self) -> impl Iterator<Item = &(E, ContentStatus)> {
213+
pub(crate) fn values(&self) -> impl Iterator<Item = &(E, ContentStatus)> {
219214
self.parts().iter().filter_map(|p| p.values()).flatten()
220215
}
221216

222-
pub fn value_count(&self) -> usize {
217+
pub(crate) fn value_count(&self) -> usize {
223218
self.values().count()
224219
}
225220
}
@@ -241,12 +236,16 @@ pub trait Store<E: RangeEntry>: Sized {
241236
fn get_first(&mut self) -> Result<E::Key, Self::Error>;
242237

243238
/// Get a single entry.
239+
#[cfg(test)]
244240
fn get(&mut self, key: &E::Key) -> Result<Option<E>, Self::Error>;
245241

246242
/// Get the number of entries in the store.
243+
#[cfg(test)]
247244
fn len(&mut self) -> Result<usize, Self::Error>;
248245

249246
/// Returns `true` if the vector contains no elements.
247+
#[cfg(test)]
248+
#[allow(unused)]
250249
fn is_empty(&mut self) -> Result<bool, Self::Error>;
251250

252251
/// Calculate the fingerprint of the given range.
@@ -274,17 +273,21 @@ pub trait Store<E: RangeEntry>: Sized {
274273
}
275274

276275
/// Returns all entries whose key starts with the given `prefix`.
276+
#[cfg(test)]
277+
#[allow(unused)]
277278
fn prefixed_by(&mut self, prefix: &E::Key) -> Result<Self::RangeIterator<'_>, Self::Error>;
278279

279280
/// Returns all entries that share a prefix with `key`, including the entry for `key` itself.
280281
fn prefixes_of(&mut self, key: &E::Key) -> Result<Self::ParentIterator<'_>, Self::Error>;
281282

282283
/// Get all entries in the store
284+
#[cfg(test)]
283285
fn all(&mut self) -> Result<Self::RangeIterator<'_>, Self::Error>;
284286

285287
/// Remove an entry from the store.
286288
///
287289
/// This will remove just the entry with the given key, but will not perform prefix deletion.
290+
#[cfg(test)]
288291
fn entry_remove(&mut self, key: &E::Key) -> Result<Option<E>, Self::Error>;
289292

290293
/// Remove all entries whose key start with a prefix and for which the `predicate` callback
@@ -602,14 +605,17 @@ impl<E: RangeEntry, S: Store<E>> Store<E> for &mut S {
602605
(**self).get_first()
603606
}
604607

608+
#[cfg(test)]
605609
fn get(&mut self, key: &<E as RangeEntry>::Key) -> Result<Option<E>, Self::Error> {
606610
(**self).get(key)
607611
}
608612

613+
#[cfg(test)]
609614
fn len(&mut self) -> Result<usize, Self::Error> {
610615
(**self).len()
611616
}
612617

618+
#[cfg(test)]
613619
fn is_empty(&mut self) -> Result<bool, Self::Error> {
614620
(**self).is_empty()
615621
}
@@ -632,6 +638,7 @@ impl<E: RangeEntry, S: Store<E>> Store<E> for &mut S {
632638
(**self).get_range(range)
633639
}
634640

641+
#[cfg(test)]
635642
fn prefixed_by(
636643
&mut self,
637644
prefix: &<E as RangeEntry>::Key,
@@ -646,10 +653,12 @@ impl<E: RangeEntry, S: Store<E>> Store<E> for &mut S {
646653
(**self).prefixes_of(key)
647654
}
648655

656+
#[cfg(test)]
649657
fn all(&mut self) -> Result<Self::RangeIterator<'_>, Self::Error> {
650658
(**self).all()
651659
}
652660

661+
#[cfg(test)]
653662
fn entry_remove(&mut self, key: &<E as RangeEntry>::Key) -> Result<Option<E>, Self::Error> {
654663
(**self).entry_remove(key)
655664
}
@@ -664,7 +673,7 @@ impl<E: RangeEntry, S: Store<E>> Store<E> for &mut S {
664673
}
665674

666675
#[derive(Debug, Clone, Copy)]
667-
pub struct SyncConfig {
676+
pub(crate) struct SyncConfig {
668677
/// Up to how many values to send immediately, before sending only a fingerprint.
669678
max_set_size: usize,
670679
/// `k` in the protocol, how many splits to generate. at least 2
@@ -682,7 +691,7 @@ impl Default for SyncConfig {
682691

683692
/// The outcome of a [`Store::put`] operation.
684693
#[derive(Debug)]
685-
pub enum InsertOutcome {
694+
pub(crate) enum InsertOutcome {
686695
/// The entry was not inserted because a newer entry for its key or a
687696
/// prefix of its key exists.
688697
NotInserted,
@@ -865,7 +874,7 @@ mod tests {
865874
}
866875

867876
#[derive(Debug)]
868-
pub struct SimpleRangeIterator<'a, K, V> {
877+
pub(crate) struct SimpleRangeIterator<'a, K, V> {
869878
iter: std::collections::btree_map::Iter<'a, K, V>,
870879
filter: SimpleFilter<K>,
871880
}
@@ -874,6 +883,8 @@ mod tests {
874883
enum SimpleFilter<K> {
875884
None,
876885
Range(Range<K>),
886+
// TODO(Frando): Add test for this.
887+
#[allow(unused)]
877888
Prefix(K),
878889
}
879890

src/store/fs.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use anyhow::{anyhow, Result};
1313
use ed25519_dalek::{SignatureError, VerifyingKey};
1414
use iroh_blobs::Hash;
1515
use rand_core::CryptoRngCore;
16-
use redb::{Database, DatabaseError, ReadableMultimapTable, ReadableTable, ReadableTableMetadata};
16+
use redb::{Database, DatabaseError, ReadableMultimapTable, ReadableTable};
1717
use tracing::warn;
1818

1919
use super::{
@@ -186,7 +186,7 @@ impl Store {
186186
///
187187
/// As such, there is also no guarantee that the data you see is
188188
/// already persisted.
189-
fn tables(&mut self) -> Result<&Tables> {
189+
fn tables(&mut self) -> Result<&Tables<'_>> {
190190
let guard = &mut self.transaction;
191191
let tables = match std::mem::take(guard) {
192192
CurrentTransaction::None => {
@@ -258,7 +258,7 @@ type PeersIter = std::vec::IntoIter<PeerIdBytes>;
258258

259259
impl Store {
260260
/// Create a new replica for `namespace` and persist in this store.
261-
pub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica> {
261+
pub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica<'_>> {
262262
let id = namespace.id();
263263
self.import_namespace(namespace.into())?;
264264
self.open_replica(&id).map_err(Into::into)
@@ -295,7 +295,7 @@ impl Store {
295295
/// Open a replica from this store.
296296
///
297297
/// This just calls load_replica_info and then creates a new replica with the info.
298-
pub fn open_replica(&mut self, namespace_id: &NamespaceId) -> Result<Replica, OpenError> {
298+
pub fn open_replica(&mut self, namespace_id: &NamespaceId) -> Result<Replica<'_>, OpenError> {
299299
let info = self.load_replica_info(namespace_id)?;
300300
let instance = StoreInstance::new(*namespace_id, self);
301301
Ok(Replica::new(instance, Box::new(info)))
@@ -465,7 +465,10 @@ impl Store {
465465
}
466466

467467
/// Get the latest entry for each author in a namespace.
468-
pub fn get_latest_for_each_author(&mut self, namespace: NamespaceId) -> Result<LatestIterator> {
468+
pub fn get_latest_for_each_author(
469+
&mut self,
470+
namespace: NamespaceId,
471+
) -> Result<LatestIterator<'_>> {
469472
LatestIterator::new(&self.tables()?.latest_per_author, namespace)
470473
}
471474

@@ -679,20 +682,24 @@ impl<'a> crate::ranger::Store<SignedEntry> for StoreInstance<'a> {
679682
Ok(id)
680683
}
681684

685+
#[cfg(test)]
682686
fn get(&mut self, id: &RecordIdentifier) -> Result<Option<SignedEntry>> {
683687
self.store
684688
.as_mut()
685689
.get_exact(id.namespace(), id.author(), id.key(), true)
686690
}
687691

692+
#[cfg(test)]
688693
fn len(&mut self) -> Result<usize> {
689694
let tables = self.store.as_mut().tables()?;
690695
let bounds = RecordsBounds::namespace(self.namespace);
691696
let records = tables.records.range(bounds.as_ref())?;
692697
Ok(records.count())
693698
}
694699

700+
#[cfg(test)]
695701
fn is_empty(&mut self) -> Result<bool> {
702+
use redb::ReadableTableMetadata;
696703
let tables = self.store.as_mut().tables()?;
697704
Ok(tables.records.is_empty()?)
698705
}
@@ -782,6 +789,7 @@ impl<'a> crate::ranger::Store<SignedEntry> for StoreInstance<'a> {
782789
Ok(iter)
783790
}
784791

792+
#[cfg(test)]
785793
fn entry_remove(&mut self, id: &RecordIdentifier) -> Result<Option<SignedEntry>> {
786794
self.store.as_mut().modify(|tables| {
787795
let entry = {
@@ -796,6 +804,7 @@ impl<'a> crate::ranger::Store<SignedEntry> for StoreInstance<'a> {
796804
})
797805
}
798806

807+
#[cfg(test)]
799808
fn all(&mut self) -> Result<Self::RangeIterator<'_>> {
800809
let tables = self.store.as_mut().tables()?;
801810
let bounds = RecordsBounds::namespace(self.namespace);
@@ -811,6 +820,7 @@ impl<'a> crate::ranger::Store<SignedEntry> for StoreInstance<'a> {
811820
ParentIterator::new(tables, id.namespace(), id.author(), id.key().to_vec())
812821
}
813822

823+
#[cfg(test)]
814824
fn prefixed_by(&mut self, id: &RecordIdentifier) -> Result<Self::RangeIterator<'_>> {
815825
let tables = self.store.as_mut().tables()?;
816826
let bounds = RecordsBounds::author_prefix(id.namespace(), id.author(), id.key_bytes());
@@ -1136,6 +1146,7 @@ mod tests {
11361146

11371147
#[test]
11381148
fn test_migration_004_populate_by_key_index() -> Result<()> {
1149+
use redb::ReadableTableMetadata;
11391150
let dbfile = tempfile::NamedTempFile::new()?;
11401151

11411152
let mut store = Store::persistent(dbfile.path())?;

src/store/fs/bounds.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl RecordsBounds {
6161
Self::new(start, Self::namespace_end(ns))
6262
}
6363

64-
pub fn as_ref(&self) -> (Bound<RecordsId>, Bound<RecordsId>) {
65-
fn map(id: &RecordsIdOwned) -> RecordsId {
64+
pub fn as_ref(&self) -> (Bound<RecordsId<'_>>, Bound<RecordsId<'_>>) {
65+
fn map(id: &RecordsIdOwned) -> RecordsId<'_> {
6666
(&id.0, &id.1, &id.2[..])
6767
}
6868
(map_bound(&self.0, map), map_bound(&self.1, map))
@@ -139,8 +139,8 @@ impl ByKeyBounds {
139139
Self(start, end)
140140
}
141141

142-
pub fn as_ref(&self) -> (Bound<RecordsByKeyId>, Bound<RecordsByKeyId>) {
143-
fn map(id: &RecordsByKeyIdOwned) -> RecordsByKeyId {
142+
pub fn as_ref(&self) -> (Bound<RecordsByKeyId<'_>>, Bound<RecordsByKeyId<'_>>) {
143+
fn map(id: &RecordsByKeyIdOwned) -> RecordsByKeyId<'_> {
144144
(&id.0, &id.1[..], &id.2)
145145
}
146146
(map_bound(&self.0, map), map_bound(&self.1, map))

0 commit comments

Comments
 (0)