Skip to content
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

Automatically deriving implementations #43

Open
vandenheuvel opened this issue Nov 6, 2018 · 9 comments
Open

Automatically deriving implementations #43

vandenheuvel opened this issue Nov 6, 2018 · 9 comments

Comments

@vandenheuvel
Copy link

Is there any outlook on automatic derivations of the traits in this crate?

I tried to write a derive crate, but got stuck. Deriving for example AbsDiffEq for structs could be done by calling AbsDiffEq::abs_diff_eq on all fields, in combination with an impl<T: Eq> AbsDiffEq for T. This last trait implementation collides however with the existing derivation implementations such as impl<'a, T: AbsDiffEq> AbsDiffEq for &'a T. I don't know how to solve this problem without removing these trait derivations, or until this work is finished.

@tylerreisinger
Copy link

Is the last blanket impl necessary? You could always just create a macro to create the implementation for foreign types if needed

@tylerreisinger
Copy link

Here's a pretty quick and dirty example of the sort of thing needed: https://gist.github.com/tylerreisinger/886e56379beffabddaff7bad6a232f06. It can only handles structs and won't insert type bounds on generics, but otherwise works.

@tylerreisinger
Copy link

Also, there is no clean way to deal with both non-primitive Epsilon types and a mix of f32/f64 types without TryFrom, which is currently unstable. I used as in my example, as I'm guessing non-primitive Epsilons aren't that common.

@aldanor
Copy link

aldanor commented Dec 25, 2018

A nice thing to have would be a derive-proc-macro, so you could do

#[derive(AbsDiffEq)]
struct MyStruct { ... }

thus avoiding all the repetitive boilerplate on a per-struct basis.

@joshburkart
Copy link

This would be really great to have! Approximately comparing nested structs/enums is a pretty common use case when writing tests for numerical computing applications. @tylerreisinger Do you think the implementation you made is ready for a PR in some form? Or too hacky right now?

@tylerreisinger
Copy link

@joshburkart It's not ready for a PR yet, but I can work on it a bit this weekend and see if I can get something working. TryFrom being stabilized helps with an issue implementing it.

@brendanzab
Copy link
Owner

Yeah, having this would be really nice! I know it'll be a bit annoying with the epsilon though, and haven't had much time at the moment to look into it.

@tylerreisinger
Copy link

I've created a repository at https://github.com/tylerreisinger/approx_derive to implement it. When it is production ready, I can transfer ownership or merge it into the approx repo with a cargo workspace.

@linclelinkpart5
Copy link

I'd love to have this as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants