These are chat archives for rust-lang/rust

24th
Jan 2017
Alexey
@KalitaAlexey
Jan 24 2017 13:33

I have main.rs:

fn foo() {}

mod tests {
    mod foo() {
        #[test]
        fn it_works() {
            super::super::foo();
        }
    }
}

Is there any different way to refer to foo?

Aleksey Kladov
@matklad
Jan 24 2017 13:35
::foo should work
Alexey
@KalitaAlexey
Jan 24 2017 13:53
@matklad,
Right. Thanks.
Clément
@claisne
Jan 24 2017 14:09
Hello everyone, I am currently playing with the ws-rs library, a websocket library based on mio. I am running two threads, one for the event loop and one for the global state. I would like to be able to broadcast from the global state thread but I am unable to do so since std::sync::mpsc::SyncSender does not satisfy std::marker::Sync.
Does anyone know how to communicate between these two threads ? I hope I am clear!
Aleksey Kladov
@matklad
Jan 24 2017 14:13

am unable to do so since std::sync::mpsc::SyncSender does not satisfy std::marker::Sync.

It should satisfy Send trait though. This means that you should be able to move this sender into the other thread.

Clément
@claisne
Jan 24 2017 14:21
You are correct, however I don't know how to move something to an other thread.
I am sorry with my beginner questions, I just started playing with rust...
Aleksey Kladov
@matklad
Jan 24 2017 14:23
This has to be done when you are creating the two threads.

I think it can look like this

val poll = // create mio poll;
val (rx, tx) = mio::channel();

let mio_thread =  std::thread::spawn(move || {
   use poll and rx here
});

let app_thread = std::thread::spawn(move || {
  use tx here
});

Does this help?

Clément
@claisne
Jan 24 2017 14:27
It does! I am trying to create a snippet to show you what I currently have (which is probably horrendous).
nevermind it too much code. I'll figure it out on my own. thanks for the help!
Aleksey Kladov
@matklad
Jan 24 2017 14:30
Good luck! The main idea is that you should create a channel before you send your event loop into the other thread.
Clément
@claisne
Jan 24 2017 14:31
Yes got it!
Alexey
@KalitaAlexey
Jan 24 2017 16:51
JSON output of rustc contains "children" field.
Which error has something in the field?