From b5cb0cce19a1e7026185f378946e0a047d8b5672 Mon Sep 17 00:00:00 2001 From: Tpt Date: Sat, 8 May 2021 07:23:14 +0200 Subject: [PATCH] Makes Clippy happy --- lib/benches/store.rs | 9 ++------- lib/src/model/xsd/date_time.rs | 18 +++++++++--------- lib/src/model/xsd/decimal.rs | 6 +++--- lib/src/model/xsd/duration.rs | 6 +++--- lib/src/storage/numeric_encoder.rs | 12 +++++------- lib/src/store.rs | 8 ++++---- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/lib/benches/store.rs b/lib/benches/store.rs index 2d71fc50..4c79ffed 100644 --- a/lib/benches/store.rs +++ b/lib/benches/store.rs @@ -2,7 +2,6 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Through use oxigraph::model::{Dataset, Graph, GraphName, NamedNode, Quad, Triple}; use oxigraph::store::Store; use rand::random; -use std::iter::FromIterator; criterion_group!( store_load, @@ -21,9 +20,7 @@ fn graph_load_bench(c: &mut Criterion) { group.throughput(Throughput::Elements(*size as u64)); let triples: Vec<_> = create_quads(*size).into_iter().map(Triple::from).collect(); group.bench_function(BenchmarkId::from_parameter(size), |b| { - b.iter(|| { - Graph::from_iter(triples.iter()); - }); + b.iter(|| triples.iter().collect::()); }); } group.finish(); @@ -37,9 +34,7 @@ fn dataset_load_bench(c: &mut Criterion) { group.throughput(Throughput::Elements(*size as u64)); let quads = create_quads(*size); group.bench_function(BenchmarkId::from_parameter(size), |b| { - b.iter(|| { - Dataset::from_iter(quads.iter()); - }); + b.iter(|| quads.iter().collect::()); }); } group.finish(); diff --git a/lib/src/model/xsd/date_time.rs b/lib/src/model/xsd/date_time.rs index 9bb8a285..f5f0170a 100644 --- a/lib/src/model/xsd/date_time.rs +++ b/lib/src/model/xsd/date_time.rs @@ -105,7 +105,7 @@ impl DateTime { } } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -284,7 +284,7 @@ impl Time { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -436,7 +436,7 @@ impl Date { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -577,7 +577,7 @@ impl GYearMonth { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -672,7 +672,7 @@ impl GYear { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -776,7 +776,7 @@ impl GMonthDay { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -867,7 +867,7 @@ impl GMonth { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -970,7 +970,7 @@ impl GDay { self.timestamp.timezone_offset() } - pub fn to_be_bytes(&self) -> [u8; 18] { + pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } @@ -1327,7 +1327,7 @@ impl Timestamp { }) } - fn to_be_bytes(&self) -> [u8; 18] { + fn to_be_bytes(self) -> [u8; 18] { let mut bytes = [0; 18]; bytes[0..16].copy_from_slice(&self.value.to_be_bytes()); bytes[16..18].copy_from_slice(&match &self.timezone_offset { diff --git a/lib/src/model/xsd/decimal.rs b/lib/src/model/xsd/decimal.rs index 52fed161..04c49a71 100644 --- a/lib/src/model/xsd/decimal.rs +++ b/lib/src/model/xsd/decimal.rs @@ -39,7 +39,7 @@ impl Decimal { } #[inline] - pub fn to_be_bytes(&self) -> [u8; 16] { + pub fn to_be_bytes(self) -> [u8; 16] { self.value.to_be_bytes() } @@ -159,7 +159,7 @@ impl Decimal { /// Creates a `f32` from a `Decimal` without taking care of precision #[inline] #[allow(clippy::cast_possible_truncation)] - pub fn to_f32(&self) -> f32 { + pub fn to_f32(self) -> f32 { self.to_f64() as f32 } @@ -175,7 +175,7 @@ impl Decimal { /// Creates a `f64` from a `Decimal` without taking care of precision #[inline] #[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)] - pub fn to_f64(&self) -> f64 { + pub fn to_f64(self) -> f64 { (self.value as f64) / (DECIMAL_PART_POW as f64) } diff --git a/lib/src/model/xsd/duration.rs b/lib/src/model/xsd/duration.rs index 5349c167..3ea41ea2 100644 --- a/lib/src/model/xsd/duration.rs +++ b/lib/src/model/xsd/duration.rs @@ -74,7 +74,7 @@ impl Duration { self.day_time.all_seconds() } - pub fn to_be_bytes(&self) -> [u8; 24] { + pub fn to_be_bytes(self) -> [u8; 24] { let mut bytes = [0; 24]; bytes[0..8].copy_from_slice(&self.year_month.to_be_bytes()); bytes[8..24].copy_from_slice(&self.day_time.to_be_bytes()); @@ -273,7 +273,7 @@ impl YearMonthDuration { self.months } - pub fn to_be_bytes(&self) -> [u8; 8] { + pub fn to_be_bytes(self) -> [u8; 8] { self.months.to_be_bytes() } @@ -425,7 +425,7 @@ impl DayTimeDuration { self.seconds } - pub fn to_be_bytes(&self) -> [u8; 16] { + pub fn to_be_bytes(self) -> [u8; 16] { self.seconds.to_be_bytes() } diff --git a/lib/src/storage/numeric_encoder.rs b/lib/src/storage/numeric_encoder.rs index 695bde75..afa92160 100644 --- a/lib/src/storage/numeric_encoder.rs +++ b/lib/src/storage/numeric_encoder.rs @@ -40,7 +40,7 @@ impl StrHash { } #[inline] - pub fn to_be_bytes(&self) -> [u8; 16] { + pub fn to_be_bytes(self) -> [u8; 16] { self.hash.to_be_bytes() } } @@ -512,8 +512,8 @@ impl From> for EncodedTerm { let datatype = literal.datatype().as_str(); let native_encoding = match datatype { "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" => { - if let Some(language) = literal.language() { - Some(if let Ok(value) = SmallString::try_from(value) { + literal.language().map(|language| { + if let Ok(value) = SmallString::try_from(value) { if let Ok(language) = SmallString::try_from(language) { EncodedTerm::SmallSmallLangStringLiteral { value, language } } else { @@ -532,10 +532,8 @@ impl From> for EncodedTerm { value_id: StrHash::new(value), language_id: StrHash::new(language), } - }) - } else { - None - } + } + }) } "http://www.w3.org/2001/XMLSchema#boolean" => parse_boolean_str(value), "http://www.w3.org/2001/XMLSchema#string" => { diff --git a/lib/src/store.rs b/lib/src/store.rs index 7f785160..4802b64c 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -812,15 +812,15 @@ fn store() -> Result<(), io::Error> { let result: Result<_, TransactionError> = store.transaction(|t| { assert!(t.remove(&default_quad)?); - assert_eq!(t.remove(&default_quad)?, false); + assert!(!t.remove(&default_quad)?); assert!(t.insert(&named_quad)?); - assert_eq!(t.insert(&named_quad)?, false); + assert!(!t.insert(&named_quad)?); assert!(t.insert(&default_quad)?); - assert_eq!(t.insert(&default_quad)?, false); + assert!(!t.insert(&default_quad)?); Ok(()) }); result?; - assert_eq!(store.insert(&default_quad)?, false); + assert!(!store.insert(&default_quad)?); assert_eq!(store.len(), 4); assert_eq!(store.iter().collect::, _>>()?, all_quads);