Crates.io | iderive |
lib.rs | iderive |
version | 1.2.3 |
source | src |
created_at | 2021-06-28 16:46:32.736524 |
updated_at | 2024-07-16 14:57:21.761882 |
description | Drop-in replacement for derive that doesn't directly depend on generic bounds |
homepage | https://github.com/maia-s/iderive |
repository | https://github.com/maia-s/iderive |
max_upload_size | |
id | 415810 |
size | 77,746 |
iderive
is a drop-in replacement for derive
that doesn't directly depend
on generic bounds. It only checks the types of a struct's fields when deriving
a trait.
#[derive(Clone, Copy)]
struct TaggedIndex<T: ?Sized> {
index: usize,
_tag: PhantomData<T>,
}
let a = TaggedIndex::<String> { index: 0, _tag: PhantomData };
let b = a;
let c = a; // Error: Value used after move
This won't work because derive
requires that T
implements Copy
for
TaggedIndex
to be able to derive it.
In contrast, iderive
only checks the struct's fields to determine if a
trait can be derived. Because usize
and PhantomData<T>
implements Copy
regardless of the type of T
, iderive(Copy)
will implement Copy
for
TaggedIndex
:
#[iderive(Clone, Copy)]
struct TaggedIndex<T: ?Sized> {
index: usize,
_tag: PhantomData<T>,
}
let a = TaggedIndex::<String> { index: 0, _tag: PhantomData };
let b = a;
let c = a; // Works!
iderive
is currently implemented for Clone
, Copy
, Debug
,
Default
, PartialEq
, Eq
, PartialOrd
, Ord
and Hash
.
#[derive(Debug)]
Debug
trait for named structsbool
typefull
featureClone
/PartialOrd
if Copy
/Ord
is also derived