These are chat archives for rust-lang/rust

29th
Aug 2017
David Harvey-Macaulay
@alteous
Aug 29 2017 15:20
How should I read *mut FnMut()?
Or even &mut FnMut()?
By read, I mean read out loud in spoken words.
David Harvey-Macaulay
@alteous
Aug 29 2017 15:36
I need some help satisfying the borrow checker. Would anyone be able to investigate this playground example for me?
stevensonmt
@stevensonmt
Aug 29 2017 16:17
Does let mut foo = |x| &xs.push(x); work for you?
David Harvey-Macaulay
@alteous
Aug 29 2017 16:18
@stevensonmt Nope, not even let mut foo = |x| (&mut xs).push(x);
stevensonmt
@stevensonmt
Aug 29 2017 16:44
The error I get after that change doesn't seem to be a borrow-lifetime issue.
error: expected expression, found keyword `mut`
  --> src/main.rs:22:30
   |
22 |     let ctx = Context { foo: mut foo };
   |                              ^^^

error[E0063]: missing field `foo` in initializer of `Context`
And removing mut from line 22 yields the error
 = note: expected type `*mut std::ops::FnMut(usize) + 'static`
              found type `[closure@src/main.rs:21:19: 21:34 xs:_]`
Joonas Koivunen
@koivunej
Aug 29 2017 17:09
@alteous i'm not sure what does a pointer to a trait object mean but your example is easily made to work by making Context generic over some F: FnMut(usize) -> () for example
@alteous perhaps this is closer to what you aimed for? https://play.rust-lang.org/?gist=305fc13151cf6561932031783f92e430&version=stable note the added block of {}
David Harvey-Macaulay
@alteous
Aug 29 2017 17:14
@koivunej That's excellent. Thank you so much! I think this solves my problem: https://play.rust-lang.org/?gist=818f204564d437dba880c5782b4acab5&version=stable
@stevensonmt Thanks for taking a look, too.
Joonas Koivunen
@koivunej
Aug 29 2017 17:15
@alteous whats the reason behind using unsafe code and raw pointers...?
David Harvey-Macaulay
@alteous
Aug 29 2017 17:16
@koivunej I have a nasty C interface to interact with.
No generics allowed!
Joonas Koivunen
@koivunej
Aug 29 2017 17:17
@alteous oh oki :) I was a bit worried there as no unsafe was needed for rust