From 001b6e07b7f1b9671930bef6d2f34a328319e823 Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 23 Jun 2023 17:17:40 +0200 Subject: [PATCH] Enforces "return self not must use" lint --- lib/oxsdatatypes/src/boolean.rs | 1 + lib/oxsdatatypes/src/date_time.rs | 102 ++++++++++++++++++++++++++++++ lib/oxsdatatypes/src/decimal.rs | 17 +++++ lib/oxsdatatypes/src/double.rs | 9 +++ lib/oxsdatatypes/src/duration.rs | 15 +++++ lib/oxsdatatypes/src/float.rs | 9 +++ lib/oxsdatatypes/src/integer.rs | 13 ++++ lib/oxsdatatypes/src/lib.rs | 1 - lib/src/lib.rs | 1 - lib/src/storage/mod.rs | 3 + lib/src/store.rs | 4 ++ 11 files changed, 173 insertions(+), 2 deletions(-) diff --git a/lib/oxsdatatypes/src/boolean.rs b/lib/oxsdatatypes/src/boolean.rs index 7ce5d977..de29debc 100644 --- a/lib/oxsdatatypes/src/boolean.rs +++ b/lib/oxsdatatypes/src/boolean.rs @@ -14,6 +14,7 @@ pub struct Boolean { impl Boolean { /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self == other } diff --git a/lib/oxsdatatypes/src/date_time.rs b/lib/oxsdatatypes/src/date_time.rs index 8d005a46..b5cc8d9e 100644 --- a/lib/oxsdatatypes/src/date_time.rs +++ b/lib/oxsdatatypes/src/date_time.rs @@ -52,6 +52,7 @@ impl DateTime { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -60,47 +61,55 @@ impl DateTime { /// [fn:year-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-year-from-dateTime) #[inline] + #[must_use] pub fn year(self) -> i64 { self.timestamp.year() } /// [fn:month-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-month-from-dateTime) #[inline] + #[must_use] pub fn month(self) -> u8 { self.timestamp.month() } /// [fn:day-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-day-from-dateTime) #[inline] + #[must_use] pub fn day(self) -> u8 { self.timestamp.day() } /// [fn:hour-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-dateTime) #[inline] + #[must_use] pub fn hour(self) -> u8 { self.timestamp.hour() } /// [fn:minute-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-dateTime) #[inline] + #[must_use] pub fn minute(self) -> u8 { self.timestamp.minute() } /// [fn:second-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-dateTime) #[inline] + #[must_use] pub fn second(self) -> Decimal { self.timestamp.second() } /// [fn:timezone-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-dateTime) #[inline] + #[must_use] pub fn timezone(self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(self) -> Option { self.timestamp.timezone_offset() } @@ -119,18 +128,21 @@ impl DateTime { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// [op:subtract-dateTimes](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dateTimes) #[inline] + #[must_use] pub fn checked_sub(self, rhs: impl Into) -> Option { self.timestamp.checked_sub(rhs.into().timestamp) } /// [op:add-yearMonthDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDuration-to-dateTime) #[inline] + #[must_use] pub fn checked_add_year_month_duration( self, rhs: impl Into, @@ -140,6 +152,7 @@ impl DateTime { /// [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-dateTime) #[inline] + #[must_use] pub fn checked_add_day_time_duration(self, rhs: impl Into) -> Option { let rhs = rhs.into(); Some(Self { @@ -149,6 +162,7 @@ impl DateTime { /// [op:add-yearMonthDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDuration-to-dateTime) and [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-dateTime) #[inline] + #[must_use] pub fn checked_add_duration(self, rhs: impl Into) -> Option { let rhs = rhs.into(); if let Ok(rhs) = DayTimeDuration::try_from(rhs) { @@ -163,6 +177,7 @@ impl DateTime { /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-dateTime) #[inline] + #[must_use] pub fn checked_sub_year_month_duration( self, rhs: impl Into, @@ -172,6 +187,7 @@ impl DateTime { /// [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-dateTime) #[inline] + #[must_use] pub fn checked_sub_day_time_duration(self, rhs: impl Into) -> Option { let rhs = rhs.into(); Some(Self { @@ -181,6 +197,7 @@ impl DateTime { /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-dateTime) and [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-dateTime) #[inline] + #[must_use] pub fn checked_sub_duration(self, rhs: impl Into) -> Option { let rhs = rhs.into(); if let Ok(rhs) = DayTimeDuration::try_from(rhs) { @@ -198,6 +215,7 @@ impl DateTime { /// [fn:adjust-dateTime-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-dateTime-to-timezone) #[inline] + #[must_use] pub fn adjust(self, timezone_offset: Option) -> Option { Some(Self { timestamp: self.timestamp.adjust(timezone_offset)?, @@ -206,6 +224,7 @@ impl DateTime { /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -300,6 +319,7 @@ impl Time { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -314,52 +334,61 @@ impl Time { /// [fn:hour-from-time](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-time) #[inline] + #[must_use] pub fn hour(self) -> u8 { self.timestamp.hour() } /// [fn:minute-from-time](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-time) #[inline] + #[must_use] pub fn minute(self) -> u8 { self.timestamp.minute() } /// [fn:second-from-time](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-time) #[inline] + #[must_use] pub fn second(self) -> Decimal { self.timestamp.second() } /// [fn:timezone-from-time](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-time) #[inline] + #[must_use] pub fn timezone(self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// [op:subtract-times](https://www.w3.org/TR/xpath-functions-31/#func-subtract-times) #[inline] + #[must_use] pub fn checked_sub(self, rhs: impl Into) -> Option { self.timestamp.checked_sub(rhs.into().timestamp) } /// [op:add-dayTimeDuration-to-time](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-time) #[inline] + #[must_use] pub fn checked_add_day_time_duration(self, rhs: impl Into) -> Option { self.checked_add_duration(Duration::from(rhs.into())) } /// [op:add-dayTimeDuration-to-time](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-time) #[inline] + #[must_use] pub fn checked_add_duration(self, rhs: impl Into) -> Option { DateTime::new( 1972, @@ -378,12 +407,14 @@ impl Time { /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-time) #[inline] + #[must_use] pub fn checked_sub_day_time_duration(self, rhs: impl Into) -> Option { self.checked_sub_duration(Duration::from(rhs.into())) } /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-time) #[inline] + #[must_use] pub fn checked_sub_duration(self, rhs: impl Into) -> Option { DateTime::new( 1972, @@ -402,6 +433,7 @@ impl Time { // [fn:adjust-time-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-time-to-timezone) #[inline] + #[must_use] pub fn adjust(self, timezone_offset: Option) -> Option { DateTime::new( 1972, @@ -420,6 +452,7 @@ impl Time { /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -501,6 +534,7 @@ impl Date { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -515,46 +549,54 @@ impl Date { /// [fn:year-from-date](https://www.w3.org/TR/xpath-functions-31/#func-year-from-date) #[inline] + #[must_use] pub fn year(self) -> i64 { self.timestamp.year() } /// [fn:month-from-date](https://www.w3.org/TR/xpath-functions-31/#func-month-from-date) #[inline] + #[must_use] pub fn month(self) -> u8 { self.timestamp.month() } /// [fn:day-from-date](https://www.w3.org/TR/xpath-functions-31/#func-day-from-date) #[inline] + #[must_use] pub fn day(self) -> u8 { self.timestamp.day() } /// [fn:timezone-from-date](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-date) #[inline] + #[must_use] pub fn timezone(self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// [op:subtract-dates](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dates) #[inline] + #[must_use] pub fn checked_sub(self, rhs: impl Into) -> Option { self.timestamp.checked_sub(rhs.into().timestamp) } /// [op:add-yearMonthDuration-to-date](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDuration-to-date) #[inline] + #[must_use] pub fn checked_add_year_month_duration( self, rhs: impl Into, @@ -564,12 +606,14 @@ impl Date { /// [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-date) #[inline] + #[must_use] pub fn checked_add_day_time_duration(self, rhs: impl Into) -> Option { self.checked_add_duration(Duration::from(rhs.into())) } /// [op:add-yearMonthDuration-to-date](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDuration-to-date) and [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-date) #[inline] + #[must_use] pub fn checked_add_duration(self, rhs: impl Into) -> Option { DateTime::try_from(self) .ok()? @@ -580,6 +624,7 @@ impl Date { /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-date) #[inline] + #[must_use] pub fn checked_sub_year_month_duration( self, rhs: impl Into, @@ -589,12 +634,14 @@ impl Date { /// [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-date) #[inline] + #[must_use] pub fn checked_sub_day_time_duration(self, rhs: impl Into) -> Option { self.checked_sub_duration(Duration::from(rhs.into())) } /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-date) and [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-date) #[inline] + #[must_use] pub fn checked_sub_duration(self, rhs: impl Into) -> Option { DateTime::try_from(self) .ok()? @@ -605,6 +652,7 @@ impl Date { // [fn:adjust-date-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-date-to-timezone) #[inline] + #[must_use] pub fn adjust(self, timezone_offset: Option) -> Option { DateTime::new( self.year(), @@ -623,6 +671,7 @@ impl Date { /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -696,6 +745,7 @@ impl GYearMonth { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -703,26 +753,31 @@ impl GYearMonth { } #[inline] + #[must_use] pub fn year(self) -> i64 { self.timestamp.year() } #[inline] + #[must_use] pub fn month(self) -> u8 { self.timestamp.month() } #[inline] + #[must_use] pub fn timezone(self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn adjust(self, timezone_offset: Option) -> Option { Some(Self { timestamp: self.timestamp.adjust(timezone_offset)?, @@ -730,12 +785,14 @@ impl GYearMonth { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -817,6 +874,7 @@ impl GYear { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -824,21 +882,25 @@ impl GYear { } #[inline] + #[must_use] pub fn year(self) -> i64 { self.timestamp.year() } #[inline] + #[must_use] pub fn timezone(self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn adjust(self, timezone_offset: Option) -> Option { Some(Self { timestamp: self.timestamp.adjust(timezone_offset)?, @@ -846,12 +908,14 @@ impl GYear { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -939,6 +1003,7 @@ impl GMonthDay { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -946,26 +1011,31 @@ impl GMonthDay { } #[inline] + #[must_use] pub fn month(&self) -> u8 { self.timestamp.month() } #[inline] + #[must_use] pub fn day(&self) -> u8 { self.timestamp.day() } #[inline] + #[must_use] pub fn timezone(&self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(&self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn adjust(&self, timezone_offset: Option) -> Option { Some(Self { timestamp: self.timestamp.adjust(timezone_offset)?, @@ -973,12 +1043,14 @@ impl GMonthDay { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -1056,6 +1128,7 @@ impl GMonth { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -1063,21 +1136,25 @@ impl GMonth { } #[inline] + #[must_use] pub fn month(&self) -> u8 { self.timestamp.month() } #[inline] + #[must_use] pub fn timezone(&self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(&self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn adjust(&self, timezone_offset: Option) -> Option { Some(Self { timestamp: self.timestamp.adjust(timezone_offset)?, @@ -1085,12 +1162,14 @@ impl GMonth { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -1182,6 +1261,7 @@ impl GDay { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 18]) -> Self { Self { timestamp: Timestamp::from_be_bytes(bytes), @@ -1189,21 +1269,25 @@ impl GDay { } #[inline] + #[must_use] pub fn day(&self) -> u8 { self.timestamp.day() } #[inline] + #[must_use] pub fn timezone(&self) -> Option { Some(self.timezone_offset()?.into()) } #[inline] + #[must_use] pub fn timezone_offset(&self) -> Option { self.timestamp.timezone_offset() } #[inline] + #[must_use] pub fn adjust(&self, timezone_offset: Option) -> Option { Some(Self { timestamp: self.timestamp.adjust(timezone_offset)?, @@ -1211,12 +1295,14 @@ impl GDay { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 18] { self.timestamp.to_be_bytes() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.timestamp.is_identical_with(other.timestamp) } @@ -1293,6 +1379,7 @@ impl TimezoneOffset { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 2]) -> Self { Self { offset: i16::from_be_bytes(bytes), @@ -1300,6 +1387,7 @@ impl TimezoneOffset { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 2] { self.offset.to_be_bytes() } @@ -1486,6 +1574,7 @@ impl Timestamp { #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] #[inline] + #[must_use] fn year_month_day(&self) -> (i64, u8, u8) { let mut days = (self.value.as_i128() + i128::from(self.timezone_offset.unwrap_or(TimezoneOffset::UTC).offset) * 60) @@ -1537,18 +1626,21 @@ impl Timestamp { } #[inline] + #[must_use] fn year(&self) -> i64 { let (year, _, _) = self.year_month_day(); year } #[inline] + #[must_use] fn month(&self) -> u8 { let (_, month, _) = self.year_month_day(); month } #[inline] + #[must_use] fn day(&self) -> u8 { let (_, _, day) = self.year_month_day(); day @@ -1556,6 +1648,7 @@ impl Timestamp { #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] #[inline] + #[must_use] fn hour(&self) -> u8 { (((self.value.as_i128() + i128::from(self.timezone_offset.unwrap_or(TimezoneOffset::UTC).offset) * 60) @@ -1565,6 +1658,7 @@ impl Timestamp { #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] #[inline] + #[must_use] fn minute(&self) -> u8 { (((self.value.as_i128() + i128::from(self.timezone_offset.unwrap_or(TimezoneOffset::UTC).offset) * 60) @@ -1573,16 +1667,19 @@ impl Timestamp { } #[inline] + #[must_use] fn second(&self) -> Decimal { self.value.checked_rem_euclid(60).unwrap().abs() } #[inline] + #[must_use] const fn timezone_offset(&self) -> Option { self.timezone_offset } #[inline] + #[must_use] fn checked_add_seconds(&self, seconds: impl Into) -> Option { Some(Self { value: self.value.checked_add(seconds.into())?, @@ -1591,6 +1688,7 @@ impl Timestamp { } #[inline] + #[must_use] fn checked_sub(&self, rhs: Self) -> Option { match (self.timezone_offset, rhs.timezone_offset) { (Some(_), Some(_)) | (None, None) => { @@ -1601,6 +1699,7 @@ impl Timestamp { } #[inline] + #[must_use] fn checked_sub_seconds(&self, seconds: Decimal) -> Option { Some(Self { value: self.value.checked_sub(seconds)?, @@ -1609,6 +1708,7 @@ impl Timestamp { } #[inline] + #[must_use] fn adjust(&self, timezone_offset: Option) -> Option { Some(if let Some(from_timezone) = self.timezone_offset { if let Some(to_timezone) = timezone_offset { @@ -1638,6 +1738,7 @@ impl Timestamp { } #[inline] + #[must_use] fn to_be_bytes(self) -> [u8; 18] { let mut bytes = [0; 18]; bytes[0..16].copy_from_slice(&self.value.to_be_bytes()); @@ -1650,6 +1751,7 @@ impl Timestamp { /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.value == other.value && self.timezone_offset == other.timezone_offset } diff --git a/lib/oxsdatatypes/src/decimal.rs b/lib/oxsdatatypes/src/decimal.rs index 412ca2b8..f3880dcb 100644 --- a/lib/oxsdatatypes/src/decimal.rs +++ b/lib/oxsdatatypes/src/decimal.rs @@ -33,6 +33,7 @@ impl Decimal { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 16]) -> Self { Self { value: i128::from_be_bytes(bytes), @@ -40,12 +41,14 @@ impl Decimal { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 16] { self.value.to_be_bytes() } /// [op:numeric-add](https://www.w3.org/TR/xpath-functions-31/#func-numeric-add) #[inline] + #[must_use] pub fn checked_add(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_add(rhs.into().value)?, @@ -54,6 +57,7 @@ impl Decimal { /// [op:numeric-subtract](https://www.w3.org/TR/xpath-functions-31/#func-numeric-subtract) #[inline] + #[must_use] pub fn checked_sub(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_sub(rhs.into().value)?, @@ -62,6 +66,7 @@ impl Decimal { /// [op:numeric-multiply](https://www.w3.org/TR/xpath-functions-31/#func-numeric-multiply) #[inline] + #[must_use] pub fn checked_mul(self, rhs: impl Into) -> Option { // Idea: we shift right as much as possible to keep as much precision as possible // Do the multiplication and do the required left shift @@ -94,6 +99,7 @@ impl Decimal { /// [op:numeric-divide](https://www.w3.org/TR/xpath-functions-31/#func-numeric-divide) #[inline] + #[must_use] pub fn checked_div(self, rhs: impl Into) -> Option { // Idea: we shift the dividend left as much as possible to keep as much precision as possible // And we shift right the divisor as much as possible @@ -127,6 +133,7 @@ impl Decimal { /// [op:numeric-mod](https://www.w3.org/TR/xpath-functions-31/#func-numeric-mod) #[inline] + #[must_use] pub fn checked_rem(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_rem(rhs.into().value)?, @@ -134,6 +141,7 @@ impl Decimal { } #[inline] + #[must_use] pub fn checked_rem_euclid(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_rem_euclid(rhs.into().value)?, @@ -142,6 +150,7 @@ impl Decimal { /// [op:numeric-unary-minus](https://www.w3.org/TR/xpath-functions-31/#func-numeric-unary-minus) #[inline] + #[must_use] pub fn checked_neg(self) -> Option { Some(Self { value: self.value.checked_neg()?, @@ -150,6 +159,7 @@ impl Decimal { /// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs) #[inline] + #[must_use] pub const fn abs(self) -> Self { Self { value: self.value.abs(), @@ -158,6 +168,7 @@ impl Decimal { /// [fn:round](https://www.w3.org/TR/xpath-functions-31/#func-round) #[inline] + #[must_use] pub fn round(self) -> Self { let value = self.value / DECIMAL_PART_POW_MINUS_ONE; Self { @@ -171,6 +182,7 @@ impl Decimal { /// [fn:ceiling](https://www.w3.org/TR/xpath-functions-31/#func-ceiling) #[inline] + #[must_use] pub fn ceil(self) -> Self { Self { value: if self.value >= 0 && self.value % DECIMAL_PART_POW != 0 { @@ -183,6 +195,7 @@ impl Decimal { /// [fn:floor](https://www.w3.org/TR/xpath-functions-31/#func-floor) #[inline] + #[must_use] pub fn floor(self) -> Self { Self { value: if self.value >= 0 || self.value % DECIMAL_PART_POW == 0 { @@ -194,22 +207,26 @@ impl Decimal { } #[inline] + #[must_use] pub const fn is_negative(self) -> bool { self.value < 0 } #[inline] + #[must_use] pub const fn is_positive(self) -> bool { self.value > 0 } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self == other } #[inline] + #[must_use] pub(super) const fn as_i128(self) -> i128 { self.value / DECIMAL_PART_POW } diff --git a/lib/oxsdatatypes/src/double.rs b/lib/oxsdatatypes/src/double.rs index 6768c772..b392d9cf 100644 --- a/lib/oxsdatatypes/src/double.rs +++ b/lib/oxsdatatypes/src/double.rs @@ -18,6 +18,7 @@ pub struct Double { impl Double { #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 8]) -> Self { Self { value: f64::from_be_bytes(bytes), @@ -25,46 +26,54 @@ impl Double { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 8] { self.value.to_be_bytes() } /// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs) #[inline] + #[must_use] pub fn abs(self) -> Self { self.value.abs().into() } /// [fn:ceiling](https://www.w3.org/TR/xpath-functions-31/#func-ceiling) #[inline] + #[must_use] pub fn ceil(self) -> Self { self.value.ceil().into() } /// [fn:floor](https://www.w3.org/TR/xpath-functions-31/#func-floor) #[inline] + #[must_use] pub fn floor(self) -> Self { self.value.floor().into() } /// [fn:round](https://www.w3.org/TR/xpath-functions-31/#func-round) #[inline] + #[must_use] pub fn round(self) -> Self { self.value.round().into() } #[inline] + #[must_use] pub fn is_nan(self) -> bool { self.value.is_nan() } #[inline] + #[must_use] pub fn is_finite(self) -> bool { self.value.is_finite() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.value.to_ne_bytes() == other.value.to_ne_bytes() } diff --git a/lib/oxsdatatypes/src/duration.rs b/lib/oxsdatatypes/src/duration.rs index 29167121..e2d9de95 100644 --- a/lib/oxsdatatypes/src/duration.rs +++ b/lib/oxsdatatypes/src/duration.rs @@ -17,6 +17,7 @@ pub struct Duration { impl Duration { #[inline] + #[must_use] pub fn new(months: impl Into, seconds: impl Into) -> Self { Self { year_month: YearMonthDuration::new(months), @@ -25,6 +26,7 @@ impl Duration { } #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 24]) -> Self { Self { year_month: YearMonthDuration::from_be_bytes(bytes[0..8].try_into().unwrap()), @@ -34,51 +36,60 @@ impl Duration { /// [fn:years-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-years-from-duration) #[inline] + #[must_use] pub fn years(self) -> i64 { self.year_month.years() } /// [fn:months-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-months-from-duration) #[inline] + #[must_use] pub fn months(self) -> i64 { self.year_month.months() } /// [fn:days-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration) #[inline] + #[must_use] pub fn days(self) -> i64 { self.day_time.days() } /// [fn:hours-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration) #[inline] + #[must_use] pub fn hours(self) -> i64 { self.day_time.hours() } /// [fn:minutes-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration) #[inline] + #[must_use] pub fn minutes(self) -> i64 { self.day_time.minutes() } /// [fn:seconds-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration) #[inline] + #[must_use] pub fn seconds(self) -> Decimal { self.day_time.seconds() } #[inline] + #[must_use] pub(super) const fn all_months(self) -> i64 { self.year_month.all_months() } #[inline] + #[must_use] pub(super) const fn all_seconds(self) -> Decimal { self.day_time.all_seconds() } #[inline] + #[must_use] 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()); @@ -88,6 +99,7 @@ impl Duration { /// [op:add-yearMonthDurations](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDurations) and [op:add-dayTimeDurations](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDurations) #[inline] + #[must_use] pub fn checked_add(self, rhs: impl Into) -> Option { let rhs = rhs.into(); Some(Self { @@ -98,6 +110,7 @@ impl Duration { /// [op:subtract-yearMonthDurations](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDurations) and [op:subtract-dayTimeDurations](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDurations) #[inline] + #[must_use] pub fn checked_sub(self, rhs: impl Into) -> Option { let rhs = rhs.into(); Some(Self { @@ -107,6 +120,7 @@ impl Duration { } #[inline] + #[must_use] pub fn checked_neg(self) -> Option { Some(Self { year_month: self.year_month.checked_neg()?, @@ -116,6 +130,7 @@ impl Duration { /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self == other } diff --git a/lib/oxsdatatypes/src/float.rs b/lib/oxsdatatypes/src/float.rs index 8c8602d3..4de94913 100644 --- a/lib/oxsdatatypes/src/float.rs +++ b/lib/oxsdatatypes/src/float.rs @@ -18,6 +18,7 @@ pub struct Float { impl Float { #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 4]) -> Self { Self { value: f32::from_be_bytes(bytes), @@ -25,46 +26,54 @@ impl Float { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 4] { self.value.to_be_bytes() } /// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs) #[inline] + #[must_use] pub fn abs(self) -> Self { self.value.abs().into() } /// [fn:ceiling](https://www.w3.org/TR/xpath-functions-31/#func-ceiling) #[inline] + #[must_use] pub fn ceil(self) -> Self { self.value.ceil().into() } /// [fn:floor](https://www.w3.org/TR/xpath-functions-31/#func-floor) #[inline] + #[must_use] pub fn floor(self) -> Self { self.value.floor().into() } /// [fn:round](https://www.w3.org/TR/xpath-functions-31/#func-round) #[inline] + #[must_use] pub fn round(self) -> Self { self.value.round().into() } #[inline] + #[must_use] pub fn is_nan(self) -> bool { self.value.is_nan() } #[inline] + #[must_use] pub fn is_finite(self) -> bool { self.value.is_finite() } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self.value.to_ne_bytes() == other.value.to_ne_bytes() } diff --git a/lib/oxsdatatypes/src/integer.rs b/lib/oxsdatatypes/src/integer.rs index 957a4b24..f376a57d 100644 --- a/lib/oxsdatatypes/src/integer.rs +++ b/lib/oxsdatatypes/src/integer.rs @@ -14,6 +14,7 @@ pub struct Integer { impl Integer { #[inline] + #[must_use] pub fn from_be_bytes(bytes: [u8; 8]) -> Self { Self { value: i64::from_be_bytes(bytes), @@ -21,12 +22,14 @@ impl Integer { } #[inline] + #[must_use] pub fn to_be_bytes(self) -> [u8; 8] { self.value.to_be_bytes() } /// [op:numeric-add](https://www.w3.org/TR/xpath-functions-31/#func-numeric-add) #[inline] + #[must_use] pub fn checked_add(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_add(rhs.into().value)?, @@ -35,6 +38,7 @@ impl Integer { /// [op:numeric-subtract](https://www.w3.org/TR/xpath-functions-31/#func-numeric-subtract) #[inline] + #[must_use] pub fn checked_sub(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_sub(rhs.into().value)?, @@ -43,6 +47,7 @@ impl Integer { /// [op:numeric-multiply](https://www.w3.org/TR/xpath-functions-31/#func-numeric-multiply) #[inline] + #[must_use] pub fn checked_mul(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_mul(rhs.into().value)?, @@ -51,6 +56,7 @@ impl Integer { /// [op:numeric-integer-divide](https://www.w3.org/TR/xpath-functions-31/#func-numeric-integer-divide) #[inline] + #[must_use] pub fn checked_div(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_div(rhs.into().value)?, @@ -59,6 +65,7 @@ impl Integer { /// [op:numeric-mod](https://www.w3.org/TR/xpath-functions-31/#func-numeric-mod) #[inline] + #[must_use] pub fn checked_rem(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_rem(rhs.into().value)?, @@ -66,6 +73,7 @@ impl Integer { } #[inline] + #[must_use] pub fn checked_rem_euclid(self, rhs: impl Into) -> Option { Some(Self { value: self.value.checked_rem_euclid(rhs.into().value)?, @@ -74,6 +82,7 @@ impl Integer { /// [op:numeric-unary-minus](https://www.w3.org/TR/xpath-functions-31/#func-numeric-unary-minus) #[inline] + #[must_use] pub fn checked_neg(self) -> Option { Some(Self { value: self.value.checked_neg()?, @@ -82,6 +91,7 @@ impl Integer { /// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs) #[inline] + #[must_use] pub const fn abs(self) -> Self { Self { value: self.value.abs(), @@ -89,17 +99,20 @@ impl Integer { } #[inline] + #[must_use] pub const fn is_negative(self) -> bool { self.value < 0 } #[inline] + #[must_use] pub const fn is_positive(self) -> bool { self.value > 0 } /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). #[inline] + #[must_use] pub fn is_identical_with(self, other: Self) -> bool { self == other } diff --git a/lib/oxsdatatypes/src/lib.rs b/lib/oxsdatatypes/src/lib.rs index 67737b13..6e1cd28f 100644 --- a/lib/oxsdatatypes/src/lib.rs +++ b/lib/oxsdatatypes/src/lib.rs @@ -3,7 +3,6 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![doc(html_favicon_url = "https://raw.githubusercontent.com/oxigraph/oxigraph/main/logo.svg")] #![doc(html_logo_url = "https://raw.githubusercontent.com/oxigraph/oxigraph/main/logo.svg")] -#![allow(clippy::return_self_not_must_use)] mod boolean; mod date_time; diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 29ef24ae..d5578fb2 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -3,7 +3,6 @@ #![doc(html_logo_url = "https://raw.githubusercontent.com/oxigraph/oxigraph/main/logo.svg")] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![doc(test(attr(deny(warnings))))] -#![allow(clippy::return_self_not_must_use)] pub mod io; pub mod sparql; diff --git a/lib/src/storage/mod.rs b/lib/src/storage/mod.rs index f1c81414..6591ac47 100644 --- a/lib/src/storage/mod.rs +++ b/lib/src/storage/mod.rs @@ -1212,16 +1212,19 @@ impl StorageBulkLoader { } } + #[must_use] pub fn set_num_threads(mut self, num_threads: usize) -> Self { self.num_threads = Some(num_threads); self } + #[must_use] pub fn set_max_memory_size_in_megabytes(mut self, max_memory_size: usize) -> Self { self.max_memory_size = Some(max_memory_size); self } + #[must_use] pub fn on_progress(mut self, callback: impl Fn(u64) + 'static) -> Self { self.hooks.push(Box::new(callback)); self diff --git a/lib/src/store.rs b/lib/src/store.rs index fc6a83f1..beb8cfd1 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -1390,6 +1390,7 @@ impl BulkLoader { /// This number must be at last 2 (one for parsing and one for loading). /// /// The default value is 2. + #[must_use] pub fn set_num_threads(mut self, num_threads: usize) -> Self { self.storage = self.storage.set_num_threads(num_threads); self @@ -1404,6 +1405,7 @@ impl BulkLoader { /// (for example if the data contains very long IRIs or literals). /// /// By default, a target 2GB per used thread is used. + #[must_use] pub fn set_max_memory_size_in_megabytes(mut self, max_memory_size: usize) -> Self { self.storage = self .storage @@ -1412,6 +1414,7 @@ impl BulkLoader { } /// Adds a `callback` evaluated from time to time with the number of loaded triples. + #[must_use] pub fn on_progress(mut self, callback: impl Fn(u64) + 'static) -> Self { self.storage = self.storage.on_progress(callback); self @@ -1421,6 +1424,7 @@ impl BulkLoader { /// by returning `Ok` or fail by returning `Err`. /// /// By default the parsing fails. + #[must_use] pub fn on_parse_error( mut self, callback: impl Fn(ParseError) -> Result<(), ParseError> + 'static,