Skip to content

Commit

Permalink
chore: apply clippy suggestions (y-crdt/y-octo#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo authored and darkskygit committed Jan 31, 2024
1 parent 7436894 commit f1c8df5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 52 deletions.
25 changes: 0 additions & 25 deletions libs/jwst-codec/src/doc/codec/id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
cmp::Ordering,
fmt::Display,
hash::Hash,
ops::{Add, Sub},
Expand Down Expand Up @@ -44,22 +43,6 @@ impl Add<Clock> for Id {
}
}

#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
impl PartialOrd for Id {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match self.client.cmp(&other.client) {
Ordering::Equal => Some(self.clock.cmp(&other.clock)),
_ => None,
}
}
}

impl Ord for Id {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.clock.cmp(&other.clock)
}
}

impl Display for Id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {})", self.client, self.clock)
Expand All @@ -72,16 +55,8 @@ mod tests {

#[test]
fn basic_id_operation() {
let id_with_same_client_1 = Id::new(1, 1);
let id_with_same_client_2 = Id::new(1, 2);
assert!(id_with_same_client_1 < id_with_same_client_2);

let id_with_different_client_1 = Id::new(1, 1);
let id_with_different_client_2 = Id::new(2, 1);
assert_eq!(
id_with_different_client_1.partial_cmp(&id_with_different_client_2),
None
);

assert_ne!(id_with_different_client_1, id_with_different_client_2);
assert_eq!(Id::new(1, 1), Id::new(1, 1));
Expand Down
21 changes: 9 additions & 12 deletions libs/jwst-codec/src/doc/common/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,15 @@ mod tests {

#[test]
fn test_range_covered() {
assert_eq!(OrderRange::check_range_covered(&[0..1], &[2..3]), false);
assert_eq!(OrderRange::check_range_covered(&[0..1], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[0..1], &[1..3]), false);
assert_eq!(OrderRange::check_range_covered(&[0..1], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[1..2], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[1..2, 2..3], &[0..3]), true);
assert_eq!(OrderRange::check_range_covered(&[1..2, 2..3, 3..4], &[0..3]), false);
assert_eq!(OrderRange::check_range_covered(&[0..1, 2..3], &[0..2, 2..4]), true);
assert_eq!(
OrderRange::check_range_covered(&[0..1, 2..3, 3..4], &[0..2, 2..4]),
true
);
assert!(!OrderRange::check_range_covered(&[0..1], &[2..3]));
assert!(OrderRange::check_range_covered(&[0..1], &[0..3]));
assert!(!OrderRange::check_range_covered(&[0..1], &[1..3]));
assert!(OrderRange::check_range_covered(&[0..1], &[0..3]));
assert!(OrderRange::check_range_covered(&[1..2], &[0..3]));
assert!(OrderRange::check_range_covered(&[1..2, 2..3], &[0..3]));
assert!(!OrderRange::check_range_covered(&[1..2, 2..3, 3..4], &[0..3]));
assert!(OrderRange::check_range_covered(&[0..1, 2..3], &[0..2, 2..4]));
assert!(OrderRange::check_range_covered(&[0..1, 2..3, 3..4], &[0..2, 2..4]),);
}

#[test]
Expand Down
7 changes: 1 addition & 6 deletions libs/jwst-codec/src/doc/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use super::Client;

#[derive(Default)]
pub struct ClientHasher(Client);

impl Hasher for ClientHasher {
Expand All @@ -19,12 +20,6 @@ impl Hasher for ClientHasher {
}
}

impl Default for ClientHasher {
fn default() -> Self {
Self(0)
}
}

#[derive(Default, Clone)]
pub struct ClientHasherBuilder;

Expand Down
4 changes: 2 additions & 2 deletions libs/jwst-codec/src/doc/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl StoreHistory {

// make items as reference
let mut store_items = store_items.iter().collect::<Vec<_>>();
store_items.sort_by(|a, b| a.id.cmp(&b.id));
store_items.sort_by(|a, b| a.id.clock.cmp(&b.id.clock));

self.parse_items(store_items)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ impl StoreHistory {

// make items as reference
let mut store_items = store_items.iter().collect::<Vec<_>>();
store_items.sort_by(|a, b| a.id.cmp(&b.id));
store_items.sort_by(|a, b| a.id.clock.cmp(&b.id.clock));

self.parse_items(store_items)
}
Expand Down
2 changes: 1 addition & 1 deletion libs/jwst-codec/src/doc/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl DocStore {
clock..clock + n.len()
})
.collect::<Vec<_>>();
if ranges.len() > 0 {
if !ranges.is_empty() {
delete_set.batch_push(*client, ranges);
}
}
Expand Down
4 changes: 2 additions & 2 deletions libs/jwst-codec/src/doc/types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Iterator for ArrayIter<'_> {
for item in self.0.by_ref() {
if let Some(item) = item.get() {
if item.countable() {
return Some(Value::try_from(&item.content).unwrap());
return Some(Value::from(&item.content));
}
}
}
Expand All @@ -40,7 +40,7 @@ impl Array {
// TODO: rewrite to content.read(&mut [Any])
return match &item.content {
Content::Any(any) => return any.get(offset as usize).map(|any| Value::Any(any.clone())),
_ => Value::try_from(&item.content).map_or_else(|_| None, Some),
_ => Some(Value::from(&item.content)),
};
}

Expand Down
8 changes: 4 additions & 4 deletions libs/jwst-codec/src/doc/types/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::hash_map::Iter;
use std::{collections::hash_map::Iter, rc::Rc};

use super::*;
use crate::{
Expand Down Expand Up @@ -71,10 +71,10 @@ pub(crate) trait MapType: AsInner<Inner = YTypeRef> {
let ty = self.as_inner().ty();

if let Some(ty) = ty {
let ty = Arc::new(ty);
let ty = Rc::new(ty);

EntriesInnerIterator {
iter: Some(unsafe { &*Arc::as_ptr(&ty) }.map.iter()),
iter: Some(unsafe { &*Rc::as_ptr(&ty) }.map.iter()),
_lock: Some(ty),
}
} else {
Expand All @@ -99,7 +99,7 @@ pub(crate) trait MapType: AsInner<Inner = YTypeRef> {
}

pub(crate) struct EntriesInnerIterator<'a> {
_lock: Option<Arc<RwLockReadGuard<'a, YType>>>,
_lock: Option<Rc<RwLockReadGuard<'a, YType>>>,
iter: Option<Iter<'a, String, ItemRef>>,
}

Expand Down

0 comments on commit f1c8df5

Please sign in to comment.