-
Notifications
You must be signed in to change notification settings - Fork 721
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
What is a good strategy to extract information out of ParseCallbacks
?
#2147
Comments
Generally interior mutability is the way we've been doing this, yeah. So a RefCell or so perhaps. The callbacks don't take mutable references because the |
Thanks for the response. It seems like I missed
That would be nice. Until then I'll make a PR to mention this in the docs (if that's okay), because I didn't find this mentioned even though |
Yeah, a PR mentioning that seems great. |
One of the advantages of doing this is that `ParseCallbacks` no longer needs to implement `UnwindSafe` which means that users can rely on `RefCell` and `Cell` to extract information from the callbacks. Users relying on `catch_unwind` can still achieve similar behavior using `std::thread::spawn`. Fixes rust-lang#2147.
You cannot use I opened #2317 which removes this restriction and uses panic hooks in the CLI. I'm not sure if anyone relies on |
One of the advantages of doing this is that `ParseCallbacks` no longer needs to implement `UnwindSafe` which means that users can rely on `RefCell` and `Cell` to extract information from the callbacks. Users relying on `catch_unwind` can still achieve similar behavior using `std::thread::spawn`. Fixes #2147.
One of the advantages of doing this is that `ParseCallbacks` no longer needs to implement `UnwindSafe` which means that users can rely on `RefCell` and `Cell` to extract information from the callbacks. Users relying on `catch_unwind` can still achieve similar behavior using `std::thread::spawn`. Fixes rust-lang#2147.
I'd like to extract information from
ParseCallbacks
so that it can be used later in the build script.For example:
I have three C macros:
VERSION_MAJOR
VERSION_MINOR
VERSION_PATCH
which all define a number and so get forwarded to
ParseCallbacks::int_macro
. Now in my implementation of that callback, I want to capture these integers for use later in the build script.Currently, as I see it, the only option is to use
Atomic*
orMutex
as the bound onParseCallbacks
specifiesUnwindSafe
which references to types with interior mutability are not, and the callbacks themselves only get a shared reference to self.This works but is not pretty and may incur performance penalties for
Mutex
.So my questions are:
(More so with a less trivial example that requires more complex data e.g.
ParseCallbacks::func_macro
)Send
/Sync
?The text was updated successfully, but these errors were encountered: