This is a known issue regarding how the function traits are inferred through Deref
. As a workaround, you need to explicitly get a mutable reference by doing a mutable reborrow:
let mut t = Foo;
(&mut *t)();
or by calling DerefMut::deref_mut
:
let mut t = Foo;
t.deref_mut()();
More Related Contents:
- When does a closure implement Fn, FnMut and FnOnce?
- Mutably borrow one struct field while borrowing another in a closure
- What is the relation between auto-dereferencing and deref coercion?
- Is it considered a bad practice to implement Deref for newtypes?
- How do I convert a Rust closure to a C-style callback?
- How to use struct self in member method closure
- Can’t borrow mutably within two different closures in the same scope
- How can I modify self in a closure called from a member function?
- Is there another option to share an Arc in multiple closures besides cloning it before each closure?
- How do I pass a closure through raw pointers as an argument to a C function?
- What are non-lexical lifetimes?
- What are Rust’s exact auto-dereferencing rules?
- How do I convert a Vector of bytes (u8) to a string?
- Is it possible to use `impl Trait` as a function’s return type in a trait definition?
- Cannot borrow as immutable because it is also borrowed as mutable in function arguments
- What is the return type of the indexing operation?
- Lifetime troubles sharing references between threads
- Moved variable still borrowing after calling `drop`?
- How do I include the end value in a range?
- How do I invoke a system command and capture its output?
- Can I destructure a tuple without binding the result to a new variable in a let/match/for statement?
- How to format output to a byte array with no_std and no allocator?
- Efficiently insert or replace multiple elements in the middle or at the beginning of a Vec?
- Calling a generic async function with a (mutably) borrowed argument
- Do all primitive types implement the Copy trait?
- Why can Serde not derive Deserialize for a struct containing only a &Path?
- How to quiet a warning for a single statement in Rust?
- Is there an elegant solution to modifying a structure while iterating?
- Can a struct containing a raw pointer implement Send and be FFI safe?
- Lazy sequence generation in Rust