| Crates.io | ignorable |
| lib.rs | ignorable |
| version | 0.1.2 |
| created_at | 2025-10-13 16:16:14.526813+00 |
| updated_at | 2025-10-13 21:15:47.511316+00 |
| description | Standard library derives that can ignore individual fields |
| homepage | |
| repository | https://github.com/nik-rev/ignorable |
| max_upload_size | |
| id | 1880741 |
| size | 50,745 |
ignorableThis crate provides 5 derives that are just like the standard library's, but they allow to ignore fields when deriving. Inspired by RFC 3869
[dependencies]
ignorable = "0.1"
This crate provides 5 derive macros:
PartialEqPartialOrdOrdDebugHashThe advantage of these derives over the standard library's is that they support
the #[ignored] attribute to ignore individual fields when deriving the respective traits.
use ignorable::{PartialEq, Hash};
// `PartialEq` and `Hash` impls will only check
// the `id` field of 2 `User`s
#[derive(Clone, PartialEq, Eq, Hash)]
struct User {
#[ignored(PartialEq, Hash)]
name: String,
#[ignored(PartialEq, Hash)]
age: u8,
id: u64
}
Advantages:
Hash and PartialEq in sync. We've got that covered!Remember that it is a logic error
for the implementations of Hash and PartialEq to differ, and if you need to manually implement the traits
to skip certain fields, you must remember to keep them in sync because you can't use the derive anymore.
ignorableUses derives provided by this crate.
use ignorable::{Debug, PartialEq, Hash};
#[derive(Clone, Debug, PartialEq, Hash)]
pub struct Var<T> {
pub ns: Symbol,
pub sym: Symbol,
#[ignored(PartialEq, Hash)]
meta: RefCell<protocols::IPersistentMap>,
#[ignored(PartialEq, Hash)]
pub root: RefCell<Rc<Value>>,
#[ignored(Debug)]
_phantom: PhantomData<T>
}
You must manually implement each trait.
#[derive(Clone)]
pub struct Var<T> {
pub ns: Symbol,
pub sym: Symbol,
meta: RefCell<protocols::IPersistentMap>,
pub root: RefCell<Rc<Value>>,
_phantom: PhantomData<T>
}
impl<T> fmt::Debug for Var<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Var")
.field("ns", &self.ns)
.field("sym", &self.sym)
.field("meta", &self.meta)
.field("root", &self.root)
.finish()
}
}
impl<T> PartialEq for Var<T> {
fn eq(&self, other: &Self) -> bool {
self.ns == other.ns && self.sym == other.sym
}
}
impl<T> Hash for Var<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
(&self.ns, &self.sym).hash(state);
}
}
Notes:
Hash and PartialEq implementations
to differ, so you must remember to keep them in sync if Var changesDebug impl if you
ever rename the fields or Var itself