-
Notifications
You must be signed in to change notification settings - Fork 250
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
Consider making EditView::on_edit take an FnMut #108
Comments
Now, In the end, pushing the That being said, I'm open to a better design allowing for nicer mutability constraints. But the main issue - that a callback with access to the TLDR: possible solutions:
|
I pushed a [dependencies]
cursive = { git="https://github.com/gyscos/cursive", branch="on_edit" } I tried to store either a |
I ended up keeping let callback = RefCell::new(callback);
move |s, text, cursor| {
if let Ok(mut callback) = callback.try_borrow_mut() {
(&mut *callback)(s, text, cursor);
}
} It ends up being a rather small change and rather isolated from the rest of the code, which would point to it not being necessary in Ideally, I'd just add a method like that: fn immutablify<Args, F: FnMut<Args>>(f: F) -> impl Fn(Args) {
let f = RefCell::new(f);
move |args: Args| {
if let Ok(f) = f.try_borrow_mut() {
(&mut *f)(args);
}
}
} But:
So for now, I'll go with the |
It should be in master as of 0bbc107. |
Seems to be the same with |
Ah yes, any place that takes a callback method will need special handling :-/ |
Oh, ok. |
That was one of the main attractive points of a |
Basically this entire Q&A https://stackoverflow.com/questions/41990175/problems-with-mutability-in-a-closure
user's comment at the bottom sums it up:
The text was updated successfully, but these errors were encountered: