Storing std::sync::Sender and Receiver in struct

Hi, for the moment I'm doing it that way, but is there a nicer way to init those fields directly in the {} braces?
And also can I store something like (tx,rx) as a tuple in that struct? I've tried but compilation failed.

pub struct FileManager {
    tx: Sender<bool>,
    rx: Receiver<bool>,
}
impl Default for FileManager {
    fn default() -> Self {
        let (tx,rx) = std::sync::mpsc::channel();
        FileManager {
            tx,
            rx,
        }
    }
}

Of course you can, if you define the struct like this:

pub struct FileManager {
    pair: (Sender<bool>, Receiver<bool>),
}

Then you would be able to simply do FileManager { pair: channel() }.

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.