XSD type structs: use by-value instead of by-ref in methods

They are small types
pull/543/head
Tpt 2 years ago
parent a8abf26913
commit 7c0563cb1b
  1. 2
      clippy.toml
  2. 2
      lib/oxsdatatypes/src/boolean.rs
  3. 138
      lib/oxsdatatypes/src/date_time.rs
  4. 30
      lib/oxsdatatypes/src/decimal.rs
  5. 8
      lib/oxsdatatypes/src/double.rs
  6. 46
      lib/oxsdatatypes/src/duration.rs
  7. 8
      lib/oxsdatatypes/src/float.rs
  8. 22
      lib/oxsdatatypes/src/integer.rs
  9. 1
      lib/src/sparql/model.rs
  10. 30
      lib/src/storage/numeric_encoder.rs

@ -1,4 +1,4 @@
avoid-breaking-exported-api = true avoid-breaking-exported-api = false
cognitive-complexity-threshold = 50 cognitive-complexity-threshold = 50
too-many-arguments-threshold = 10 too-many-arguments-threshold = 10
type-complexity-threshold = 500 type-complexity-threshold = 500

@ -14,7 +14,7 @@ pub struct Boolean {
impl Boolean { impl Boolean {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self == other self == other
} }
} }

@ -60,53 +60,53 @@ impl DateTime {
/// [fn:year-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-year-from-dateTime) /// [fn:year-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-year-from-dateTime)
#[inline] #[inline]
pub fn year(&self) -> i64 { pub fn year(self) -> i64 {
self.timestamp.year() self.timestamp.year()
} }
/// [fn:month-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-month-from-dateTime) /// [fn:month-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-month-from-dateTime)
#[inline] #[inline]
pub fn month(&self) -> u8 { pub fn month(self) -> u8 {
self.timestamp.month() self.timestamp.month()
} }
/// [fn:day-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-day-from-dateTime) /// [fn:day-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-day-from-dateTime)
#[inline] #[inline]
pub fn day(&self) -> u8 { pub fn day(self) -> u8 {
self.timestamp.day() self.timestamp.day()
} }
/// [fn:hour-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-dateTime) /// [fn:hour-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-dateTime)
#[inline] #[inline]
pub fn hour(&self) -> u8 { pub fn hour(self) -> u8 {
self.timestamp.hour() self.timestamp.hour()
} }
/// [fn:minute-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-dateTime) /// [fn:minute-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-dateTime)
#[inline] #[inline]
pub fn minute(&self) -> u8 { pub fn minute(self) -> u8 {
self.timestamp.minute() self.timestamp.minute()
} }
/// [fn:second-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-dateTime) /// [fn:second-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-dateTime)
#[inline] #[inline]
pub fn second(&self) -> Decimal { pub fn second(self) -> Decimal {
self.timestamp.second() self.timestamp.second()
} }
/// [fn:timezone-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-dateTime) /// [fn:timezone-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-dateTime)
#[inline] #[inline]
pub fn timezone(&self) -> Option<DayTimeDuration> { pub fn timezone(self) -> Option<DayTimeDuration> {
Some(self.timezone_offset()?.into()) Some(self.timezone_offset()?.into())
} }
#[inline] #[inline]
pub fn timezone_offset(&self) -> Option<TimezoneOffset> { pub fn timezone_offset(self) -> Option<TimezoneOffset> {
self.timestamp.timezone_offset() self.timestamp.timezone_offset()
} }
#[inline] #[inline]
fn properties(&self) -> DateTimeSevenPropertyModel { fn properties(self) -> DateTimeSevenPropertyModel {
DateTimeSevenPropertyModel { DateTimeSevenPropertyModel {
year: Some(self.year()), year: Some(self.year()),
month: Some(self.month()), month: Some(self.month()),
@ -125,14 +125,14 @@ impl DateTime {
/// [op:subtract-dateTimes](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dateTimes) /// [op:subtract-dateTimes](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dateTimes)
#[inline] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<DayTimeDuration> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<DayTimeDuration> {
self.timestamp.checked_sub(rhs.into().timestamp) 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) /// [op:add-yearMonthDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDuration-to-dateTime)
#[inline] #[inline]
pub fn checked_add_year_month_duration( pub fn checked_add_year_month_duration(
&self, self,
rhs: impl Into<YearMonthDuration>, rhs: impl Into<YearMonthDuration>,
) -> Option<Self> { ) -> Option<Self> {
self.checked_add_duration(Duration::from(rhs.into())) self.checked_add_duration(Duration::from(rhs.into()))
@ -140,7 +140,7 @@ impl DateTime {
/// [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-dateTime) /// [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-dateTime)
#[inline] #[inline]
pub fn checked_add_day_time_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_add_day_time_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
timestamp: self.timestamp.checked_add_seconds(rhs.all_seconds())?, timestamp: self.timestamp.checked_add_seconds(rhs.all_seconds())?,
@ -149,7 +149,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) /// [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] #[inline]
pub fn checked_add_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_add_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
if let Ok(rhs) = DayTimeDuration::try_from(rhs) { if let Ok(rhs) = DayTimeDuration::try_from(rhs) {
self.checked_add_day_time_duration(rhs) self.checked_add_day_time_duration(rhs)
@ -164,7 +164,7 @@ impl DateTime {
/// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-dateTime) /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-dateTime)
#[inline] #[inline]
pub fn checked_sub_year_month_duration( pub fn checked_sub_year_month_duration(
&self, self,
rhs: impl Into<YearMonthDuration>, rhs: impl Into<YearMonthDuration>,
) -> Option<Self> { ) -> Option<Self> {
self.checked_sub_duration(Duration::from(rhs.into())) self.checked_sub_duration(Duration::from(rhs.into()))
@ -172,7 +172,7 @@ impl DateTime {
/// [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-dateTime) /// [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-dateTime)
#[inline] #[inline]
pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_sub_day_time_duration(self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
timestamp: self.timestamp.checked_sub_seconds(rhs.all_seconds())?, timestamp: self.timestamp.checked_sub_seconds(rhs.all_seconds())?,
@ -181,7 +181,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) /// [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] #[inline]
pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_sub_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
if let Ok(rhs) = DayTimeDuration::try_from(rhs) { if let Ok(rhs) = DayTimeDuration::try_from(rhs) {
self.checked_sub_day_time_duration(rhs) self.checked_sub_day_time_duration(rhs)
@ -198,7 +198,7 @@ impl DateTime {
/// [fn:adjust-dateTime-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-dateTime-to-timezone) /// [fn:adjust-dateTime-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-dateTime-to-timezone)
#[inline] #[inline]
pub fn adjust(&self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> { pub fn adjust(self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> {
Some(Self { Some(Self {
timestamp: self.timestamp.adjust(timezone_offset)?, timestamp: self.timestamp.adjust(timezone_offset)?,
}) })
@ -206,8 +206,8 @@ impl DateTime {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -314,30 +314,30 @@ impl Time {
/// [fn:hour-from-time](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-time) /// [fn:hour-from-time](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-time)
#[inline] #[inline]
pub fn hour(&self) -> u8 { pub fn hour(self) -> u8 {
self.timestamp.hour() self.timestamp.hour()
} }
/// [fn:minute-from-time](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-time) /// [fn:minute-from-time](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-time)
#[inline] #[inline]
pub fn minute(&self) -> u8 { pub fn minute(self) -> u8 {
self.timestamp.minute() self.timestamp.minute()
} }
/// [fn:second-from-time](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-time) /// [fn:second-from-time](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-time)
#[inline] #[inline]
pub fn second(&self) -> Decimal { pub fn second(self) -> Decimal {
self.timestamp.second() self.timestamp.second()
} }
/// [fn:timezone-from-time](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-time) /// [fn:timezone-from-time](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-time)
#[inline] #[inline]
pub fn timezone(&self) -> Option<DayTimeDuration> { pub fn timezone(self) -> Option<DayTimeDuration> {
Some(self.timezone_offset()?.into()) Some(self.timezone_offset()?.into())
} }
#[inline] #[inline]
pub fn timezone_offset(&self) -> Option<TimezoneOffset> { pub fn timezone_offset(self) -> Option<TimezoneOffset> {
self.timestamp.timezone_offset() self.timestamp.timezone_offset()
} }
@ -348,19 +348,19 @@ impl Time {
/// [op:subtract-times](https://www.w3.org/TR/xpath-functions-31/#func-subtract-times) /// [op:subtract-times](https://www.w3.org/TR/xpath-functions-31/#func-subtract-times)
#[inline] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<DayTimeDuration> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<DayTimeDuration> {
self.timestamp.checked_sub(rhs.into().timestamp) 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) /// [op:add-dayTimeDuration-to-time](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-time)
#[inline] #[inline]
pub fn checked_add_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_add_day_time_duration(self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
self.checked_add_duration(Duration::from(rhs.into())) 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) /// [op:add-dayTimeDuration-to-time](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-time)
#[inline] #[inline]
pub fn checked_add_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_add_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
DateTime::new( DateTime::new(
1972, 1972,
12, 12,
@ -378,13 +378,13 @@ impl Time {
/// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-time) /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-time)
#[inline] #[inline]
pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_sub_day_time_duration(self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
self.checked_sub_duration(Duration::from(rhs.into())) 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) /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-time)
#[inline] #[inline]
pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_sub_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
DateTime::new( DateTime::new(
1972, 1972,
12, 12,
@ -402,7 +402,7 @@ impl Time {
// [fn:adjust-time-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-time-to-timezone) // [fn:adjust-time-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-time-to-timezone)
#[inline] #[inline]
pub fn adjust(&self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> { pub fn adjust(self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> {
DateTime::new( DateTime::new(
1972, 1972,
12, 12,
@ -420,8 +420,8 @@ impl Time {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -515,30 +515,30 @@ impl Date {
/// [fn:year-from-date](https://www.w3.org/TR/xpath-functions-31/#func-year-from-date) /// [fn:year-from-date](https://www.w3.org/TR/xpath-functions-31/#func-year-from-date)
#[inline] #[inline]
pub fn year(&self) -> i64 { pub fn year(self) -> i64 {
self.timestamp.year() self.timestamp.year()
} }
/// [fn:month-from-date](https://www.w3.org/TR/xpath-functions-31/#func-month-from-date) /// [fn:month-from-date](https://www.w3.org/TR/xpath-functions-31/#func-month-from-date)
#[inline] #[inline]
pub fn month(&self) -> u8 { pub fn month(self) -> u8 {
self.timestamp.month() self.timestamp.month()
} }
/// [fn:day-from-date](https://www.w3.org/TR/xpath-functions-31/#func-day-from-date) /// [fn:day-from-date](https://www.w3.org/TR/xpath-functions-31/#func-day-from-date)
#[inline] #[inline]
pub fn day(&self) -> u8 { pub fn day(self) -> u8 {
self.timestamp.day() self.timestamp.day()
} }
/// [fn:timezone-from-date](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-date) /// [fn:timezone-from-date](https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-date)
#[inline] #[inline]
pub fn timezone(&self) -> Option<DayTimeDuration> { pub fn timezone(self) -> Option<DayTimeDuration> {
Some(self.timezone_offset()?.into()) Some(self.timezone_offset()?.into())
} }
#[inline] #[inline]
pub fn timezone_offset(&self) -> Option<TimezoneOffset> { pub fn timezone_offset(self) -> Option<TimezoneOffset> {
self.timestamp.timezone_offset() self.timestamp.timezone_offset()
} }
@ -549,14 +549,14 @@ impl Date {
/// [op:subtract-dates](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dates) /// [op:subtract-dates](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dates)
#[inline] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<DayTimeDuration> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<DayTimeDuration> {
self.timestamp.checked_sub(rhs.into().timestamp) 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) /// [op:add-yearMonthDuration-to-date](https://www.w3.org/TR/xpath-functions-31/#func-add-yearMonthDuration-to-date)
#[inline] #[inline]
pub fn checked_add_year_month_duration( pub fn checked_add_year_month_duration(
&self, self,
rhs: impl Into<YearMonthDuration>, rhs: impl Into<YearMonthDuration>,
) -> Option<Self> { ) -> Option<Self> {
self.checked_add_duration(Duration::from(rhs.into())) self.checked_add_duration(Duration::from(rhs.into()))
@ -564,14 +564,14 @@ impl Date {
/// [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-date) /// [op:add-dayTimeDuration-to-dateTime](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDuration-to-date)
#[inline] #[inline]
pub fn checked_add_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_add_day_time_duration(self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
self.checked_add_duration(Duration::from(rhs.into())) 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) /// [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] #[inline]
pub fn checked_add_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_add_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
DateTime::try_from(*self) DateTime::try_from(self)
.ok()? .ok()?
.checked_add_duration(rhs)? .checked_add_duration(rhs)?
.try_into() .try_into()
@ -581,7 +581,7 @@ impl Date {
/// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-date) /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-yearMonthDuration-from-date)
#[inline] #[inline]
pub fn checked_sub_year_month_duration( pub fn checked_sub_year_month_duration(
&self, self,
rhs: impl Into<YearMonthDuration>, rhs: impl Into<YearMonthDuration>,
) -> Option<Self> { ) -> Option<Self> {
self.checked_sub_duration(Duration::from(rhs.into())) self.checked_sub_duration(Duration::from(rhs.into()))
@ -589,14 +589,14 @@ impl Date {
/// [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-date) /// [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDuration-from-date)
#[inline] #[inline]
pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_sub_day_time_duration(self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
self.checked_sub_duration(Duration::from(rhs.into())) 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) /// [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] #[inline]
pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_sub_duration(self, rhs: impl Into<Duration>) -> Option<Self> {
DateTime::try_from(*self) DateTime::try_from(self)
.ok()? .ok()?
.checked_sub_duration(rhs)? .checked_sub_duration(rhs)?
.try_into() .try_into()
@ -605,7 +605,7 @@ impl Date {
// [fn:adjust-date-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-date-to-timezone) // [fn:adjust-date-to-timezone](https://www.w3.org/TR/xpath-functions-31/#func-adjust-date-to-timezone)
#[inline] #[inline]
pub fn adjust(&self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> { pub fn adjust(self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> {
DateTime::new( DateTime::new(
self.year(), self.year(),
self.month(), self.month(),
@ -623,8 +623,8 @@ impl Date {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -703,27 +703,27 @@ impl GYearMonth {
} }
#[inline] #[inline]
pub fn year(&self) -> i64 { pub fn year(self) -> i64 {
self.timestamp.year() self.timestamp.year()
} }
#[inline] #[inline]
pub fn month(&self) -> u8 { pub fn month(self) -> u8 {
self.timestamp.month() self.timestamp.month()
} }
#[inline] #[inline]
pub fn timezone(&self) -> Option<DayTimeDuration> { pub fn timezone(self) -> Option<DayTimeDuration> {
Some(self.timezone_offset()?.into()) Some(self.timezone_offset()?.into())
} }
#[inline] #[inline]
pub fn timezone_offset(&self) -> Option<TimezoneOffset> { pub fn timezone_offset(self) -> Option<TimezoneOffset> {
self.timestamp.timezone_offset() self.timestamp.timezone_offset()
} }
#[inline] #[inline]
pub fn adjust(&self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> { pub fn adjust(self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> {
Some(Self { Some(Self {
timestamp: self.timestamp.adjust(timezone_offset)?, timestamp: self.timestamp.adjust(timezone_offset)?,
}) })
@ -736,8 +736,8 @@ impl GYearMonth {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -824,22 +824,22 @@ impl GYear {
} }
#[inline] #[inline]
pub fn year(&self) -> i64 { pub fn year(self) -> i64 {
self.timestamp.year() self.timestamp.year()
} }
#[inline] #[inline]
pub fn timezone(&self) -> Option<DayTimeDuration> { pub fn timezone(self) -> Option<DayTimeDuration> {
Some(self.timezone_offset()?.into()) Some(self.timezone_offset()?.into())
} }
#[inline] #[inline]
pub fn timezone_offset(&self) -> Option<TimezoneOffset> { pub fn timezone_offset(self) -> Option<TimezoneOffset> {
self.timestamp.timezone_offset() self.timestamp.timezone_offset()
} }
#[inline] #[inline]
pub fn adjust(&self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> { pub fn adjust(self, timezone_offset: Option<TimezoneOffset>) -> Option<Self> {
Some(Self { Some(Self {
timestamp: self.timestamp.adjust(timezone_offset)?, timestamp: self.timestamp.adjust(timezone_offset)?,
}) })
@ -852,8 +852,8 @@ impl GYear {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -979,8 +979,8 @@ impl GMonthDay {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -1091,8 +1091,8 @@ impl GMonth {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -1217,8 +1217,8 @@ impl GDay {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.timestamp.is_identical_with(&other.timestamp) self.timestamp.is_identical_with(other.timestamp)
} }
} }
@ -1650,7 +1650,7 @@ impl Timestamp {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.value == other.value && self.timezone_offset == other.timezone_offset self.value == other.value && self.timezone_offset == other.timezone_offset
} }
} }

@ -47,7 +47,7 @@ impl Decimal {
/// [op:numeric-add](https://www.w3.org/TR/xpath-functions-31/#func-numeric-add) /// [op:numeric-add](https://www.w3.org/TR/xpath-functions-31/#func-numeric-add)
#[inline] #[inline]
pub fn checked_add(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_add(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_add(rhs.into().value)?, value: self.value.checked_add(rhs.into().value)?,
}) })
@ -55,7 +55,7 @@ impl Decimal {
/// [op:numeric-subtract](https://www.w3.org/TR/xpath-functions-31/#func-numeric-subtract) /// [op:numeric-subtract](https://www.w3.org/TR/xpath-functions-31/#func-numeric-subtract)
#[inline] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_sub(rhs.into().value)?, value: self.value.checked_sub(rhs.into().value)?,
}) })
@ -63,7 +63,7 @@ impl Decimal {
/// [op:numeric-multiply](https://www.w3.org/TR/xpath-functions-31/#func-numeric-multiply) /// [op:numeric-multiply](https://www.w3.org/TR/xpath-functions-31/#func-numeric-multiply)
#[inline] #[inline]
pub fn checked_mul(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_mul(self, rhs: impl Into<Self>) -> Option<Self> {
// Idea: we shift right as much as possible to keep as much precision as possible // Idea: we shift right as much as possible to keep as much precision as possible
// Do the multiplication and do the required left shift // Do the multiplication and do the required left shift
let mut left = self.value; let mut left = self.value;
@ -95,7 +95,7 @@ impl Decimal {
/// [op:numeric-divide](https://www.w3.org/TR/xpath-functions-31/#func-numeric-divide) /// [op:numeric-divide](https://www.w3.org/TR/xpath-functions-31/#func-numeric-divide)
#[inline] #[inline]
pub fn checked_div(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_div(self, rhs: impl Into<Self>) -> Option<Self> {
// Idea: we shift the dividend left as much as possible to keep as much precision as possible // 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 // And we shift right the divisor as much as possible
// Do the multiplication and do the required shift // Do the multiplication and do the required shift
@ -128,14 +128,14 @@ impl Decimal {
/// [op:numeric-mod](https://www.w3.org/TR/xpath-functions-31/#func-numeric-mod) /// [op:numeric-mod](https://www.w3.org/TR/xpath-functions-31/#func-numeric-mod)
#[inline] #[inline]
pub fn checked_rem(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_rem(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_rem(rhs.into().value)?, value: self.value.checked_rem(rhs.into().value)?,
}) })
} }
#[inline] #[inline]
pub fn checked_rem_euclid(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_rem_euclid(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_rem_euclid(rhs.into().value)?, value: self.value.checked_rem_euclid(rhs.into().value)?,
}) })
@ -143,7 +143,7 @@ impl Decimal {
/// [op:numeric-unary-minus](https://www.w3.org/TR/xpath-functions-31/#func-numeric-unary-minus) /// [op:numeric-unary-minus](https://www.w3.org/TR/xpath-functions-31/#func-numeric-unary-minus)
#[inline] #[inline]
pub fn checked_neg(&self) -> Option<Self> { pub fn checked_neg(self) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_neg()?, value: self.value.checked_neg()?,
}) })
@ -151,7 +151,7 @@ impl Decimal {
/// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs) /// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs)
#[inline] #[inline]
pub const fn abs(&self) -> Self { pub const fn abs(self) -> Self {
Self { Self {
value: self.value.abs(), value: self.value.abs(),
} }
@ -159,7 +159,7 @@ impl Decimal {
/// [fn:round](https://www.w3.org/TR/xpath-functions-31/#func-round) /// [fn:round](https://www.w3.org/TR/xpath-functions-31/#func-round)
#[inline] #[inline]
pub fn round(&self) -> Self { pub fn round(self) -> Self {
let value = self.value / DECIMAL_PART_POW_MINUS_ONE; let value = self.value / DECIMAL_PART_POW_MINUS_ONE;
Self { Self {
value: if value >= 0 { value: if value >= 0 {
@ -172,7 +172,7 @@ impl Decimal {
/// [fn:ceiling](https://www.w3.org/TR/xpath-functions-31/#func-ceiling) /// [fn:ceiling](https://www.w3.org/TR/xpath-functions-31/#func-ceiling)
#[inline] #[inline]
pub fn ceil(&self) -> Self { pub fn ceil(self) -> Self {
Self { Self {
value: if self.value >= 0 && self.value % DECIMAL_PART_POW != 0 { value: if self.value >= 0 && self.value % DECIMAL_PART_POW != 0 {
(self.value / DECIMAL_PART_POW + 1) * DECIMAL_PART_POW (self.value / DECIMAL_PART_POW + 1) * DECIMAL_PART_POW
@ -184,7 +184,7 @@ impl Decimal {
/// [fn:floor](https://www.w3.org/TR/xpath-functions-31/#func-floor) /// [fn:floor](https://www.w3.org/TR/xpath-functions-31/#func-floor)
#[inline] #[inline]
pub fn floor(&self) -> Self { pub fn floor(self) -> Self {
Self { Self {
value: if self.value >= 0 || self.value % DECIMAL_PART_POW == 0 { value: if self.value >= 0 || self.value % DECIMAL_PART_POW == 0 {
(self.value / DECIMAL_PART_POW) * DECIMAL_PART_POW (self.value / DECIMAL_PART_POW) * DECIMAL_PART_POW
@ -195,23 +195,23 @@ impl Decimal {
} }
#[inline] #[inline]
pub const fn is_negative(&self) -> bool { pub const fn is_negative(self) -> bool {
self.value < 0 self.value < 0
} }
#[inline] #[inline]
pub const fn is_positive(&self) -> bool { pub const fn is_positive(self) -> bool {
self.value > 0 self.value > 0
} }
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self == other self == other
} }
#[inline] #[inline]
pub(super) const fn as_i128(&self) -> i128 { pub(super) const fn as_i128(self) -> i128 {
self.value / DECIMAL_PART_POW self.value / DECIMAL_PART_POW
} }

@ -71,7 +71,7 @@ impl Double {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.value.to_ne_bytes() == other.value.to_ne_bytes() self.value.to_ne_bytes() == other.value.to_ne_bytes()
} }
@ -291,9 +291,9 @@ mod tests {
#[test] #[test]
fn is_identical_with() { fn is_identical_with() {
assert!(Double::from(0.).is_identical_with(&Double::from(0.))); assert!(Double::from(0.).is_identical_with(Double::from(0.)));
assert!(Double::NAN.is_identical_with(&Double::NAN)); assert!(Double::NAN.is_identical_with(Double::NAN));
assert!(!Double::from(-0.).is_identical_with(&Double::from(0.))); assert!(!Double::from(-0.).is_identical_with(Double::from(0.)));
} }
#[test] #[test]

@ -35,47 +35,47 @@ impl Duration {
/// [fn:years-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-years-from-duration) /// [fn:years-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-years-from-duration)
#[inline] #[inline]
pub fn years(&self) -> i64 { pub fn years(self) -> i64 {
self.year_month.years() self.year_month.years()
} }
/// [fn:months-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-months-from-duration) /// [fn:months-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-months-from-duration)
#[inline] #[inline]
pub fn months(&self) -> i64 { pub fn months(self) -> i64 {
self.year_month.months() self.year_month.months()
} }
/// [fn:days-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration) /// [fn:days-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration)
#[inline] #[inline]
pub fn days(&self) -> i64 { pub fn days(self) -> i64 {
self.day_time.days() self.day_time.days()
} }
/// [fn:hours-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration) /// [fn:hours-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration)
#[inline] #[inline]
pub fn hours(&self) -> i64 { pub fn hours(self) -> i64 {
self.day_time.hours() self.day_time.hours()
} }
/// [fn:minutes-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration) /// [fn:minutes-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration)
#[inline] #[inline]
pub fn minutes(&self) -> i64 { pub fn minutes(self) -> i64 {
self.day_time.minutes() self.day_time.minutes()
} }
/// [fn:seconds-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration) /// [fn:seconds-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration)
#[inline] #[inline]
pub fn seconds(&self) -> Decimal { pub fn seconds(self) -> Decimal {
self.day_time.seconds() self.day_time.seconds()
} }
#[inline] #[inline]
pub(super) const fn all_months(&self) -> i64 { pub(super) const fn all_months(self) -> i64 {
self.year_month.all_months() self.year_month.all_months()
} }
#[inline] #[inline]
pub(super) const fn all_seconds(&self) -> Decimal { pub(super) const fn all_seconds(self) -> Decimal {
self.day_time.all_seconds() self.day_time.all_seconds()
} }
@ -89,7 +89,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) /// [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] #[inline]
pub fn checked_add(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_add(self, rhs: impl Into<Self>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
year_month: self.year_month.checked_add(rhs.year_month)?, year_month: self.year_month.checked_add(rhs.year_month)?,
@ -99,7 +99,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) /// [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] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
year_month: self.year_month.checked_sub(rhs.year_month)?, year_month: self.year_month.checked_sub(rhs.year_month)?,
@ -108,7 +108,7 @@ impl Duration {
} }
#[inline] #[inline]
pub fn checked_neg(&self) -> Option<Self> { pub fn checked_neg(self) -> Option<Self> {
Some(Self { Some(Self {
year_month: self.year_month.checked_neg()?, year_month: self.year_month.checked_neg()?,
day_time: self.day_time.checked_neg()?, day_time: self.day_time.checked_neg()?,
@ -117,7 +117,7 @@ impl Duration {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self == other self == other
} }
} }
@ -308,7 +308,7 @@ impl YearMonthDuration {
} }
#[inline] #[inline]
pub fn checked_neg(&self) -> Option<Self> { pub fn checked_neg(self) -> Option<Self> {
Some(Self { Some(Self {
months: self.months.checked_neg()?, months: self.months.checked_neg()?,
}) })
@ -316,7 +316,7 @@ impl YearMonthDuration {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self == other self == other
} }
} }
@ -428,32 +428,32 @@ impl DayTimeDuration {
/// [fn:days-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration) /// [fn:days-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration)
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
#[inline] #[inline]
pub fn days(&self) -> i64 { pub fn days(self) -> i64 {
(self.seconds.as_i128() / 86400) as i64 (self.seconds.as_i128() / 86400) as i64
} }
/// [fn:hours-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration) /// [fn:hours-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration)
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
#[inline] #[inline]
pub fn hours(&self) -> i64 { pub fn hours(self) -> i64 {
((self.seconds.as_i128() % 86400) / 3600) as i64 ((self.seconds.as_i128() % 86400) / 3600) as i64
} }
/// [fn:minutes-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration) /// [fn:minutes-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration)
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
#[inline] #[inline]
pub fn minutes(&self) -> i64 { pub fn minutes(self) -> i64 {
((self.seconds.as_i128() % 3600) / 60) as i64 ((self.seconds.as_i128() % 3600) / 60) as i64
} }
/// [fn:seconds-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration) /// [fn:seconds-from-duration](https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration)
#[inline] #[inline]
pub fn seconds(&self) -> Decimal { pub fn seconds(self) -> Decimal {
self.seconds.checked_rem(60).unwrap() self.seconds.checked_rem(60).unwrap()
} }
#[inline] #[inline]
pub(super) const fn all_seconds(&self) -> Decimal { pub(super) const fn all_seconds(self) -> Decimal {
self.seconds self.seconds
} }
@ -464,7 +464,7 @@ impl DayTimeDuration {
/// [op:add-dayTimeDurations](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDurations) /// [op:add-dayTimeDurations](https://www.w3.org/TR/xpath-functions-31/#func-add-dayTimeDurations)
#[inline] #[inline]
pub fn checked_add(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_add(self, rhs: impl Into<Self>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
seconds: self.seconds.checked_add(rhs.seconds)?, seconds: self.seconds.checked_add(rhs.seconds)?,
@ -473,7 +473,7 @@ impl DayTimeDuration {
/// [op:subtract-dayTimeDurations](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDurations) /// [op:subtract-dayTimeDurations](https://www.w3.org/TR/xpath-functions-31/#func-subtract-dayTimeDurations)
#[inline] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
seconds: self.seconds.checked_sub(rhs.seconds)?, seconds: self.seconds.checked_sub(rhs.seconds)?,
@ -481,7 +481,7 @@ impl DayTimeDuration {
} }
#[inline] #[inline]
pub fn checked_neg(&self) -> Option<Self> { pub fn checked_neg(self) -> Option<Self> {
Some(Self { Some(Self {
seconds: self.seconds.checked_neg()?, seconds: self.seconds.checked_neg()?,
}) })
@ -489,7 +489,7 @@ impl DayTimeDuration {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self == other self == other
} }
} }

@ -71,7 +71,7 @@ impl Float {
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self.value.to_ne_bytes() == other.value.to_ne_bytes() self.value.to_ne_bytes() == other.value.to_ne_bytes()
} }
@ -281,9 +281,9 @@ mod tests {
#[test] #[test]
fn is_identical_with() { fn is_identical_with() {
assert!(Float::from(0.).is_identical_with(&Float::from(0.))); assert!(Float::from(0.).is_identical_with(Float::from(0.)));
assert!(Float::NAN.is_identical_with(&Float::NAN)); assert!(Float::NAN.is_identical_with(Float::NAN));
assert!(!Float::from(-0.).is_identical_with(&Float::from(0.))); assert!(!Float::from(-0.).is_identical_with(Float::from(0.)));
} }
#[test] #[test]

@ -28,7 +28,7 @@ impl Integer {
/// [op:numeric-add](https://www.w3.org/TR/xpath-functions-31/#func-numeric-add) /// [op:numeric-add](https://www.w3.org/TR/xpath-functions-31/#func-numeric-add)
#[inline] #[inline]
pub fn checked_add(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_add(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_add(rhs.into().value)?, value: self.value.checked_add(rhs.into().value)?,
}) })
@ -36,7 +36,7 @@ impl Integer {
/// [op:numeric-subtract](https://www.w3.org/TR/xpath-functions-31/#func-numeric-subtract) /// [op:numeric-subtract](https://www.w3.org/TR/xpath-functions-31/#func-numeric-subtract)
#[inline] #[inline]
pub fn checked_sub(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_sub(rhs.into().value)?, value: self.value.checked_sub(rhs.into().value)?,
}) })
@ -44,7 +44,7 @@ impl Integer {
/// [op:numeric-multiply](https://www.w3.org/TR/xpath-functions-31/#func-numeric-multiply) /// [op:numeric-multiply](https://www.w3.org/TR/xpath-functions-31/#func-numeric-multiply)
#[inline] #[inline]
pub fn checked_mul(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_mul(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_mul(rhs.into().value)?, value: self.value.checked_mul(rhs.into().value)?,
}) })
@ -52,7 +52,7 @@ impl Integer {
/// [op:numeric-divide](https://www.w3.org/TR/xpath-functions-31/#func-numeric-divide) /// [op:numeric-divide](https://www.w3.org/TR/xpath-functions-31/#func-numeric-divide)
#[inline] #[inline]
pub fn checked_div(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_div(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_div(rhs.into().value)?, value: self.value.checked_div(rhs.into().value)?,
}) })
@ -60,14 +60,14 @@ impl Integer {
/// [op:numeric-mod](https://www.w3.org/TR/xpath-functions-31/#func-numeric-mod) /// [op:numeric-mod](https://www.w3.org/TR/xpath-functions-31/#func-numeric-mod)
#[inline] #[inline]
pub fn checked_rem(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_rem(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_rem(rhs.into().value)?, value: self.value.checked_rem(rhs.into().value)?,
}) })
} }
#[inline] #[inline]
pub fn checked_rem_euclid(&self, rhs: impl Into<Self>) -> Option<Self> { pub fn checked_rem_euclid(self, rhs: impl Into<Self>) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_rem_euclid(rhs.into().value)?, value: self.value.checked_rem_euclid(rhs.into().value)?,
}) })
@ -75,7 +75,7 @@ impl Integer {
/// [op:numeric-unary-minus](https://www.w3.org/TR/xpath-functions-31/#func-numeric-unary-minus) /// [op:numeric-unary-minus](https://www.w3.org/TR/xpath-functions-31/#func-numeric-unary-minus)
#[inline] #[inline]
pub fn checked_neg(&self) -> Option<Self> { pub fn checked_neg(self) -> Option<Self> {
Some(Self { Some(Self {
value: self.value.checked_neg()?, value: self.value.checked_neg()?,
}) })
@ -83,25 +83,25 @@ impl Integer {
/// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs) /// [fn:abs](https://www.w3.org/TR/xpath-functions-31/#func-abs)
#[inline] #[inline]
pub const fn abs(&self) -> Self { pub const fn abs(self) -> Self {
Self { Self {
value: self.value.abs(), value: self.value.abs(),
} }
} }
#[inline] #[inline]
pub const fn is_negative(&self) -> bool { pub const fn is_negative(self) -> bool {
self.value < 0 self.value < 0
} }
#[inline] #[inline]
pub const fn is_positive(&self) -> bool { pub const fn is_positive(self) -> bool {
self.value > 0 self.value > 0
} }
/// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity). /// Checks if the two values are [identical](https://www.w3.org/TR/xmlschema11-2/#identity).
#[inline] #[inline]
pub fn is_identical_with(&self, other: &Self) -> bool { pub fn is_identical_with(self, other: Self) -> bool {
self == other self == other
} }

@ -167,6 +167,7 @@ pub struct QuerySolutionIter {
} }
impl QuerySolutionIter { impl QuerySolutionIter {
#[allow(clippy::rc_buffer)]
pub fn new( pub fn new(
variables: Rc<Vec<Variable>>, variables: Rc<Vec<Variable>>,
iter: impl Iterator<Item = Result<Vec<Option<Term>>, EvaluationError>> + 'static, iter: impl Iterator<Item = Result<Vec<Option<Term>>, EvaluationError>> + 'static,

@ -183,24 +183,24 @@ impl PartialEq for EncodedTerm {
}, },
) => value_id_a == value_id_b && datatype_id_a == datatype_id_b, ) => value_id_a == value_id_b && datatype_id_a == datatype_id_b,
(Self::BooleanLiteral(a), Self::BooleanLiteral(b)) => a == b, (Self::BooleanLiteral(a), Self::BooleanLiteral(b)) => a == b,
(Self::FloatLiteral(a), Self::FloatLiteral(b)) => a.is_identical_with(b), (Self::FloatLiteral(a), Self::FloatLiteral(b)) => a.is_identical_with(*b),
(Self::DoubleLiteral(a), Self::DoubleLiteral(b)) => a.is_identical_with(b), (Self::DoubleLiteral(a), Self::DoubleLiteral(b)) => a.is_identical_with(*b),
(Self::IntegerLiteral(a), Self::IntegerLiteral(b)) => a.is_identical_with(b), (Self::IntegerLiteral(a), Self::IntegerLiteral(b)) => a.is_identical_with(*b),
(Self::DecimalLiteral(a), Self::DecimalLiteral(b)) => a.is_identical_with(b), (Self::DecimalLiteral(a), Self::DecimalLiteral(b)) => a.is_identical_with(*b),
(Self::DateTimeLiteral(a), Self::DateTimeLiteral(b)) => a.is_identical_with(b), (Self::DateTimeLiteral(a), Self::DateTimeLiteral(b)) => a.is_identical_with(*b),
(Self::TimeLiteral(a), Self::TimeLiteral(b)) => a.is_identical_with(b), (Self::TimeLiteral(a), Self::TimeLiteral(b)) => a.is_identical_with(*b),
(Self::DateLiteral(a), Self::DateLiteral(b)) => a.is_identical_with(b), (Self::DateLiteral(a), Self::DateLiteral(b)) => a.is_identical_with(*b),
(Self::GYearMonthLiteral(a), Self::GYearMonthLiteral(b)) => a.is_identical_with(b), (Self::GYearMonthLiteral(a), Self::GYearMonthLiteral(b)) => a.is_identical_with(*b),
(Self::GYearLiteral(a), Self::GYearLiteral(b)) => a.is_identical_with(b), (Self::GYearLiteral(a), Self::GYearLiteral(b)) => a.is_identical_with(*b),
(Self::GMonthDayLiteral(a), Self::GMonthDayLiteral(b)) => a.is_identical_with(b), (Self::GMonthDayLiteral(a), Self::GMonthDayLiteral(b)) => a.is_identical_with(*b),
(Self::GMonthLiteral(a), Self::GMonthLiteral(b)) => a.is_identical_with(b), (Self::GMonthLiteral(a), Self::GMonthLiteral(b)) => a.is_identical_with(*b),
(Self::GDayLiteral(a), Self::GDayLiteral(b)) => a.is_identical_with(b), (Self::GDayLiteral(a), Self::GDayLiteral(b)) => a.is_identical_with(*b),
(Self::DurationLiteral(a), Self::DurationLiteral(b)) => a.is_identical_with(b), (Self::DurationLiteral(a), Self::DurationLiteral(b)) => a.is_identical_with(*b),
(Self::YearMonthDurationLiteral(a), Self::YearMonthDurationLiteral(b)) => { (Self::YearMonthDurationLiteral(a), Self::YearMonthDurationLiteral(b)) => {
a.is_identical_with(b) a.is_identical_with(*b)
} }
(Self::DayTimeDurationLiteral(a), Self::DayTimeDurationLiteral(b)) => { (Self::DayTimeDurationLiteral(a), Self::DayTimeDurationLiteral(b)) => {
a.is_identical_with(b) a.is_identical_with(*b)
} }
(Self::Triple(a), Self::Triple(b)) => a == b, (Self::Triple(a), Self::Triple(b)) => a == b,
(_, _) => false, (_, _) => false,

Loading…
Cancel
Save