-
Notifications
You must be signed in to change notification settings - Fork 22
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
mod ipred
: Use wrap_fn_ptr!
to generate decl_fn!
s and add type-safe wrappers
#581
Conversation
fa0e67f
to
5bda2e8
Compare
4a29b5d
to
97662d8
Compare
What is the |
Yeah, the alternative to a token type is to just make a newtype, but since most of the rest besides that token type part can be a generic type, I thought it's easier that way as less code has to be inside the macro. |
The Token type is hard to understand, IMO. It took me a bit to figure out what the actual problem was, because I forgot that we were even using a pub type instead of a fresh newtype. I think the newtype is the way to go here, whether the code is inside or outside the macro doesn't matter here because we don't use |
5bda2e8
to
336bb06
Compare
97662d8
to
0956cc2
Compare
I tried out declaring the newtype inside the macro and it is indeed a lot cleaner and simpler. |
…e copied when moved and compared for equality.
…uate different `fn` ptrs with the same signature.
… `decl_fn!`s with `wrap_fn_ptr!` and add type-safe wrappers.
… type with a newtype in the macro. This puts more code inside the macro, but also simplifies a bunch of things. It also lets us make the methods on `Fn` `pub(super)`, as they only need to be called by the declaring module.
…implemented. Co-authored-by: Stephen Crane <[email protected]>
0956cc2
to
c1ee39a
Compare
c1ee39a
to
e885327
Compare
This also reworks
wrap_fn_ptr!
to declareFn
as a newtypestruct
inside the macro rather than a type alias to the genericWrappedFnPtr
, which needed a type token for disambiguation. This results in mode code inside the macro vs. out of it, but the code is much simpler and easier to understand this way.