AsyncClient

Struct AsyncClient 

Source
pub struct AsyncClient<S>(/* private fields */);
Available on crate feature async only.
Expand description

A connection to the Sawfish window manager using asynchronous I/O.

Implementations§

Source§

impl AsyncClient<Compat<UnixStream>>

Source

pub async fn open(display: Option<&str>) -> Result<Self, ConnError>

Available on crate feature tokio only.

Opens a connection to the Sawfish server using the Tokio runtime.

The display argument specifies an optional display string, (such as ":0"). If not provided, the DISPLAY environment variable is used.

Source§

impl<S: AsyncRead + AsyncWrite + Unpin> AsyncClient<S>

Source

pub fn new(socket: S) -> Self

Constructs a connection to the Sawfish server over an asynchronous Unix socket.

Because the creation of an asynchronous Unix socket depends on the async runtime, responsibility to open the connection falls on the caller. Use server_path to determine path to the Unix Socket the Sawfish server is (supposed to be) listening on.

§Example
use tokio_util::compat::TokioAsyncReadCompatExt;

type TokioClient = sawfish_client::AsyncClient<
    tokio_util::compat::Compat<tokio::net::UnixStream>>;

async fn open() -> TokioClient {
    let path = sawfish_client::server_path(None).unwrap();
    let sock = tokio::net::UnixStream::connect(path).await.unwrap();
    sawfish_client::AsyncClient::new(sock.compat())
}
Source

pub async fn eval( &mut self, form: impl AsRef<[u8]>, ) -> Result<EvalResponse, EvalError>

Sends a Lisp form to the Sawfish server for evaluation and waits for a reply.

  • If there’s an error sending the form to the server (e.g. an I/O error), returns an Err(error) value.
  • Otherwise, if the form has been successfully sent to the server but evaluation failed (e.g. due to syntax error), returns Ok(Err(data)) value.
  • Otherwise, if the form has been successfully executed by the server, returns Ok(Ok(data)) value.
§Example
use futures_util::{AsyncRead, AsyncWrite};

async fn system_name<S: AsyncRead + AsyncWrite + Unpin>(
    client: &mut sawfish_client::AsyncClient<S>,
) -> Option<String> {
    match client.eval("(system-name)").await {
        Ok(Ok(data)) => {
            Some(String::from_utf8_lossy(&data).into_owned())
        }
        Ok(Err(data)) => {
            println!("Error evaluating form: {}",
                     String::from_utf8_lossy(&data));
            None
        }
        Err(err) => {
            println!("Communication error: {err}");
            None
        }
    }
}
Source

pub async fn send(&mut self, form: impl AsRef<[u8]>) -> Result<(), EvalError>

Sends a Lisp form to the Sawfish server for evaluation but does not wait for a reply.

If there’s an error sending the form to the server (e.g. an I/O error), returns an Err(error) value. Otherwise, so long as the form was successfully sent, returns Ok(()) even if evaluation on the server side has changed (e.g. due to syntax error). Use Self::eval instead to check whether evaluation succeeded.

§Example
use futures_util::{AsyncRead, AsyncWrite};

async fn set_screen_viewport<S: AsyncRead + AsyncWrite + Unpin>(
    client: &mut sawfish_client::AsyncClient<S>,
    x: u32,
    y: u32,
) {
    let form = format!("(set-screen-viewport {x} {y})");
    if let Err(err) = client.send(&form).await {
        println!("Communication error: {err}");
    }
}

Auto Trait Implementations§

§

impl<S> Freeze for AsyncClient<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for AsyncClient<S>
where S: RefUnwindSafe,

§

impl<S> Send for AsyncClient<S>
where S: Send,

§

impl<S> Sync for AsyncClient<S>
where S: Sync,

§

impl<S> Unpin for AsyncClient<S>
where S: Unpin,

§

impl<S> UnwindSafe for AsyncClient<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.