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

Detouring a function with a reference parameter #9

Open
whatisaphone opened this issue Apr 10, 2019 · 2 comments
Open

Detouring a function with a reference parameter #9

whatisaphone opened this issue Apr 10, 2019 · 2 comments

Comments

@whatisaphone
Copy link

Something goes wrong deep in the innards of the macro when you try to detour an extern "Rust" function that takes a reference as a parameter:

static_detours! {
    struct DetourPrintln: fn(&str);
}
error[E0308]: mismatched types
  --> crates\core\src\lib.rs:21:5
   |
21 | /     static_detours! {
22 | |         pub struct DetourPrintln: fn(&str);
23 | |     }
   | |_____^ one type is more general than the other
   |
   = note: expected type `detour::Function`
              found type `detour::Function`
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
@darfink
Copy link
Owner

darfink commented Apr 11, 2019

That's correct.
The Function trait cannot express lifetime semantics of individual arguments and has therefore a 'static requirement (so functions with reference arguments do not implement it).

An alternative is to use the more cumbersome RawDetour.

Perhaps there is a potentially better alternative implementation but I've yet to identify a solution that is type-safe.

@whatisaphone
Copy link
Author

I understand. That's an unfortunate limitation. Thanks for the explanation and workaround 👍

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

2 participants