Allow Clippy lint: derive_hash_xor_eq
The implementation is identical to how #[derive] would do it, and we use the implementation to add some documentation warning people not to use items with nanosecond-level precision in hash maps unless they're sure that's what they want.
This commit is contained in:
parent
4c18d701ca
commit
5643b845a5
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
//! ISO 8601 calendar date without timezone.
|
//! ISO 8601 calendar date without timezone.
|
||||||
|
|
||||||
use std::{str, fmt, hash};
|
use std::{str, fmt};
|
||||||
use std::ops::{Add, Sub, AddAssign, SubAssign};
|
use std::ops::{Add, Sub, AddAssign, SubAssign};
|
||||||
use num::traits::ToPrimitive;
|
use num::traits::ToPrimitive;
|
||||||
use oldtime::Duration as OldDuration;
|
use oldtime::Duration as OldDuration;
|
||||||
|
@ -93,7 +93,7 @@ const MAX_BITS: usize = 44;
|
||||||
/// The year number is same to that of the [calendar date](#calendar-date).
|
/// The year number is same to that of the [calendar date](#calendar-date).
|
||||||
///
|
///
|
||||||
/// This is currently the internal format of Chrono's date types.
|
/// This is currently the internal format of Chrono's date types.
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone)]
|
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)]
|
||||||
pub struct NaiveDate {
|
pub struct NaiveDate {
|
||||||
ymdf: DateImpl, // (year << 13) | of
|
ymdf: DateImpl, // (year << 13) | of
|
||||||
}
|
}
|
||||||
|
@ -1302,14 +1302,6 @@ impl Datelike for NaiveDate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `NaiveDate` can be used as a key to the hash maps.
|
|
||||||
impl hash::Hash for NaiveDate {
|
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
|
||||||
// don't need to strip flags, as we can safely assume that it is correct
|
|
||||||
self.ymdf.hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An addition of `Duration` to `NaiveDate` discards the fractional days,
|
/// An addition of `Duration` to `NaiveDate` discards the fractional days,
|
||||||
/// rounding to the closest integral number of days towards `Duration::zero()`.
|
/// rounding to the closest integral number of days towards `Duration::zero()`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1103,6 +1103,7 @@ impl Timelike for NaiveDateTime {
|
||||||
///
|
///
|
||||||
/// Practically this also takes account of fractional seconds, so it is not recommended.
|
/// Practically this also takes account of fractional seconds, so it is not recommended.
|
||||||
/// (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)
|
/// (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))]
|
||||||
impl hash::Hash for NaiveDateTime {
|
impl hash::Hash for NaiveDateTime {
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
self.date.hash(state);
|
self.date.hash(state);
|
||||||
|
|
|
@ -981,6 +981,7 @@ impl Timelike for NaiveTime {
|
||||||
///
|
///
|
||||||
/// Practically this also takes account of fractional seconds, so it is not recommended.
|
/// Practically this also takes account of fractional seconds, so it is not recommended.
|
||||||
/// (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)
|
/// (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)
|
||||||
|
#[cfg_attr(feature = "cargo-clippy", allow(derive_hash_xor_eq))]
|
||||||
impl hash::Hash for NaiveTime {
|
impl hash::Hash for NaiveTime {
|
||||||
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
self.secs.hash(state);
|
self.secs.hash(state);
|
||||||
|
|
Loading…
Reference in New Issue