Passing Rust code to macro

    let (exporter_handle, tx) = go_thread!("exporter", ||
       { serve_file_properties(&export, &responder); }
    ,
        let context = zmq::Context::new();
        let responder = context.socket(zmq::REP).expect("Failed to create REP socket");
        responder.bind("tcp://127.0.0.1:5555").expect("Failed to bind socket");
        
    );

I wanted to create a macro that spawns a thread, which can be terminated at any time by the main thread through a channel. I wanted the ability to define some context as well, and I found it fascinating that you can create a macro, pass Rust code as an argument, and then use variables defined there in closure.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.