-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: remove derivative dep #34
Conversation
I would prefer to switch to one of the alternatives as we also use derivative extensively in Lighthouse Have you used derive_more or educe? |
I think I prefer the look of |
Ah, didn't realise that derive_more doesn't allow customisation of PartialEq, etc. I guess this means we go with educe. |
right, looks like derive_more doesn't support custom bounds. although the tradeoff here is +~15 lines vs an additional dep |
I think Rust's derive has actually gotten smarter and we don't need any custom implementations at all.
impl<T: ::core::cmp::PartialEq> ::core::cmp::PartialEq for Bitfield<T> {
#[inline]
fn eq(&self, other: &Bitfield<T>) -> bool {
self.bytes == other.bytes && self.len == other.len
&& self._phantom == other._phantom
}
}
impl<T: ::core::hash::Hash> ::core::hash::Hash for Bitfield<T> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
::core::hash::Hash::hash(&self.bytes, state);
::core::hash::Hash::hash(&self.len, state);
::core::hash::Hash::hash(&self._phantom, state)
}
} Which is perfect. No extra bounds. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #34 +/- ##
=======================================
Coverage 77.76% 77.76%
=======================================
Files 12 12
Lines 715 715
=======================================
Hits 556 556
Misses 159 159 ☔ View full report in Codecov by Sentry. |
There are still bounds with the builtin derive ( Changing to builtin derives is a breaking change; I don't know the impact or if this is acceptable for you, just a heads up |
Oh damn I totally read that wrong |
Fixing here: |
there's an advisory for derivative https://rustsec.org/advisories/RUSTSEC-2024-0388
replaces derivative dep with the expanded code (omits phantom field, because noop)
expanded code on main: