#partial-eq #api-testing

deprecated macro timeless-partialeq

[DEPRECATED] PartialEq, but ignores timestamps, ideal for API testing

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

Download history 10/week @ 2024-07-30 5/week @ 2024-09-10 2/week @ 2024-09-17 2/week @ 2024-09-24 7/week @ 2024-10-01

282 downloads per month

AGPL-3.0-or-later

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