Expand description
Ignore fields in PartialEq custom implementations.
§Examples
use skippable_partialeq::SkippablePartialEq;
use chrono::{DateTime, TimeZone, Utc};
#[derive(Debug, SkippablePartialEq)]
#[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()),
}
) // trueYou can also skip specific fields that do not follow a pattern using the #[skip] attribute above the fields you want to ignore:
use skippable_partialeq::SkippablePartialEq;
use chrono::{DateTime, TimeZone, Utc};
#[derive(Debug, SkippablePartialEq)]
pub struct Post {
pub id: i64,
pub content: String,
pub author: i32,
#[skip]
pub creation_date: DateTime<Utc>,
}
assert_eq!(
Post {
id: 1,
content: "test".to_string(),
author: 1,
creation_date: Utc.timestamp_millis_opt(1715017040672).unwrap(),
},
Post {
id: 1,
content: "test".to_string(),
author: 1,
creation_date: Utc::now(),
}
)