4 releases
0.2.1 | Jun 20, 2024 |
---|---|
0.2.0 | May 9, 2024 |
0.1.1 | May 7, 2024 |
0.1.0 | May 6, 2024 |
#35 in #partial-eq
282 downloads per month
15KB
60 lines
DEPECRATED -> NEW CRATE: SkippablePartialEq
lib.rs
:
Ignore fields ending with a specific suffix in PartialEq custom implementations.
Examples
use timeless_partialeq::TimelessPartialEq;
use chrono::{DateTime, TimeZone, Utc};
#[derive(Debug, TimelessPartialEq)]
#[exclude_suffix(at, date)]
pub struct Post {
pub id: i64,
pub content: String,
pub author: i32,
pub creation_date: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
}
assert_eq!(
Post {
id: 1,
content: "test".to_string(),
author: 1,
creation_date: Utc.timestamp_millis_opt(1715017040672).unwrap(),
updated_at: Some(Utc.timestamp_millis_opt(1715017020672).unwrap()),
},
Post {
id: 1,
content: "test".to_string(),
author: 1,
creation_date: Utc::now(),
updated_at: Some(Utc::now()),
}
) // true
About the crate
This crate was made to solve a very specific problem: assert the equality of two objects despite the timestamp differences. It was also made so that I could study proc macros. However, just after a day after publishing it, I realized that it can be broader than just timestamps.
I will not make a commitment into iterating this quickly, but it is in my plans to expand the scope of the crate.
Dependencies
~260–710KB
~17K SLoC