Writing to UnixStream

How can I write to a UnixStream? Many examples use write_all() but the compiler says that there's no write_all in the scope and tells me to include std::io::Write. Which I did and the problem persists.

pub mod fallback {
    pub fn run() {
        log::warn!("Another instance is already running.");
        log::info!("Trying to communicate with the previous instance.");
        log::info!("Trying to connect with the previous socket server.");

        let uds_name = crate::backend::generate_uds_name();
        let socket = std::path::Path::new(&uds_name);

        match std::os::unix::net::UnixStream::connect(&socket) {
            Err(e) => {
                // TODO: HANDLE THIS
                log::error!("Socket not running: {}.", e);
                panic!();
            }
            Ok(stream) => {
                log::info!("Server connected successfully.");
                match stream.write_all(b"prompt") {
                    Ok(_) => log::info!("Sent message to the UDS server"),
                    // TODO: HANDLE THIS
                    Err(_) => log::error!("Message sending failed"),
                }
            }
        }
    }
}


error[E0599]: no method named `write_all` found for type `std::os::unix::net::UnixStream` in the current scope
  --> src/app.rs:60:30
   |
60 |                 match stream.write_all(b"prompt") {
   |                              ^^^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           `use std::io::Write;`

error: aborting due to previous error

Do you have:

use std::os::unix::net::UnixStream;
use std::io::prelude::*;

Ah, the problem was that the includes were outside the mod{} block. Silly of me indeed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.