These are chat archives for rust-lang/rust

22nd
Oct 2018
Sackery
@sackery
Oct 22 2018 11:53
Why unresolved import proc_macro?
Ayush Prashar
@ayushprashar
Oct 22 2018 12:07
Hey guys
Quick question, why is it compulsory to give the data type when declaring a constant
?
red75prime
@red75prime
Oct 22 2018 12:38
To prevent type inference from crossing function boundaries. It is by design to reduce "non-local effects" of type inference.
Sackery
@sackery
Oct 22 2018 13:25
mismatched types

expected struct `proc_macro::TokenStream`, found struct `proc_macro2::TokenStream`

note: expected type `fn(proc_macro::TokenStream) -> proc_macro::TokenStream`
         found type `fn(proc_macro2::TokenStream) -> proc_macro2::TokenStream {derive_enum_number}`
how to fix it?
cubetastic
@cubetastic33
Oct 22 2018 14:51
Is it possible to turn off the computer screen temporarily using rust?
Or is it possible to bring a full black window on top of the running windows using rust? Which would be a better choice if both can be done?
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:25
I'm sure both can be done. Probably the full-screen black window is better because you don't want to completely take over the display manager.
And not every computer controls the montitor's power switch, either.
cubetastic
@cubetastic33
Oct 22 2018 15:26
so how do I make a full screen black window?
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:26
Depends on your stack: Windows, GNOME, KDE, OSX, etc.
cubetastic
@cubetastic33
Oct 22 2018 15:27
GNOME
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:27
Well, I don't know the answer for any of them, myself.
cubetastic
@cubetastic33
Oct 22 2018 15:27
oh.
do u know where I should look?
Someplace like winit?
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:28
The dev docs. I'm sure there's something for making a fullscreen window.
cubetastic
@cubetastic33
Oct 22 2018 15:28
dev docs of rust?
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:28
No, of Gnome.
cubetastic
@cubetastic33
Oct 22 2018 15:29
oh
?
That doesn't seem to make sense - I want to do this using rust, why would the GNOME docs tell me how to do it?
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:29
GTK, I guess. You'll probably have to do some FFI and call the API.
cubetastic
@cubetastic33
Oct 22 2018 15:30
oh. but then, can't I just use any other GUI crate?
Lyle Mantooth
@IslandUsurper
Oct 22 2018 15:30
Maybe. If they expose that in their API.
cubetastic
@cubetastic33
Oct 22 2018 15:30
ok .great. thanks a lot!
tandrysyawaludin
@tandrysyawaludin
Oct 22 2018 16:28
how to make compiling process Rust faster?
Victor Lopes
@vlopes11
Oct 22 2018 19:07

Colleagues, I have a struct A, a method B of this struct who received a mutable self, and inside this method I create a closure that needs also to receive a mutable reference to A. Smth like this:

struct A {}

impl A {
pub fn B(&mut self) {
self.something(|| {
self.other_method_required_mutable();
});
}
}

What's the best way to do this? I can use several Arcs, but then it could get messy
skeleten
@skeleten
Oct 22 2018 19:42
(tip: write three backticks in a line before and after code, to format it properly)
Thiez
@Thiez
Oct 22 2018 20:01
@vlopes11 that looks like a weird design, could you describe why you need this? What are you trying to accomplish?
Zakarum
@omni-viral
Oct 22 2018 20:42
@vlopes11 you'd need to split self into parts and borrow them mutably. Then one method would use one part, another method - another part. You can't possibly borrow self mutably more than once
The only other way I see is to provide &mut self back into closure as argument
struct A {}
impl A {
  pub fn B(&mut self) {
    self.something(|this| {
      this.other_method_required_mutable();
    });
  }
}
This will only work if you don't borrow any parts of self inside something at the moment you call provided closure