Giter Site home page Giter Site logo

caioluis / skippable-partialeq Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 34 KB

PartialEq, but you can ignore struct fields

Home Page: https://docs.rs/skippable-partialeq/

License: GNU Affero General Public License v3.0

Rust 100.00%
partialeq rust testing

skippable-partialeq's Introduction

skippable-partialeq

PartialEq, but you can ignore fields

This crate provides a custom derive macro SkippablePartialEq that allows you to implement PartialEq for structs while ignoring fields based on custom rules such as suffixes, as well as specific fields.

Usage

First, add SkippablePartialEq as a dependency.

cargo add skippable-partialeq

Then, derive SkippablePartialEq for your struct:

use skippable_partialeq::SkippablePartialEq;

#[derive(Debug, SkippablePartialEq)]
#[exclude_suffix(at)]
pub struct Post {
    pub id: i64,
    pub content: String,
    pub author: i32,
    pub created_at: DateTime<Utc>,
    pub updated_at: Option<DateTime<Utc>>,
}

This will generate an implementation of PartialEq that ignores the fields ending with _at, while still checking for Option's outer None & Some values. This attribute supports multiple values separated by comma.

You can also use the #[skip] attribute to filter by specific fields:

use skippable_partialeq::SkippablePartialEq;

#[derive(Debug, SkippablePartialEq)]
pub struct Post {
    pub id: i64,
    pub content: String,
    pub author: i32,
    #[skip]
    pub creation_date: DateTime<Utc>,
}

This would exclude creation_date from the comparison.

skippable-partialeq's People

Contributors

caioluis avatar

Stargazers

Tiago Carvalho avatar Wesley Alves avatar Lucas Cruz dos Reis avatar  avatar Hanniel Vieira avatar Nathan Miguel avatar

Watchers

 avatar

skippable-partialeq's Issues

Be able to exclude prefix

We currently either exclude fields ending with suffixes that match our arguments array inside exclude_suffix() attribute. It would be nice if we could also exclude based on prefixes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.