Skip to main content

send_command

Function send_command 

Source
pub fn send_command(
    cmd: Command,
    socket_name: &str,
    socket_type: &SocketType,
) -> Result<Response, Error>
Expand description

Executes a single daemon command on a new connection and closes it.

Warning: if this function returns the Ok variant, this only means that the command was successfully delivered to the daemon. It doesn’t necessarily mean it was executed successfully on the daemon side.

§Examples

match send_command(Command::Ping, DEFAULT_SOCKET_NAME, &SocketType::default()) {
    // The `Ok` variant only means the command was delivered
    Ok(response) => {
        match response {
            Response::Ok => eprintln!("Got an `Ok` response, all good!"),
            // Depending on the type of command sent, the response from the daemon may be different.
            _ => panic!("Got an unexpected response: {response:?}"),
        }
    },
    Err(error) => panic!("Could not send a command to the daemon: {error}"),
}