Socket

Struct Socket 

Source
pub struct Socket<S> { /* private fields */ }

Implementations§

Source§

impl<S: SocketStream> Socket<S>

Source

pub async fn connect() -> Result<Self, Error>

Connects to the default niri IPC socket.

This is the async version of Socket::connect

Source

pub async fn connect_to(path: impl AsRef<Path>) -> Result<Self, Error>

Connects to the niri IPC socket at the given path.

This is the async version of Socket::connect_to

Source

pub async fn send(&mut self, request: Request) -> Result<Reply, Error>

Sends a request to niri and returns the response.

This is the async version of Socket::send

Source

pub async fn into_event_stream( self, ) -> Result<impl Stream<Item = Result<Event, Error>>, IntoEventStreamError>

Send request and reading event stream Events from the socket.

Note that unlike the Socket::read_events, this method will send an EventStream request.

§Examples
use niri_ipc::{Request, Response};
use niri_ipc::socket::Socket;

async fn print_events() -> Result<(), std::io::Error> {
    let mut socket = Socket::connect().await?;

    let reply = socket.into_event_stream().await;
    if let Ok(event_stream) = reply {
        let read_event = std::pin::pin!(event_stream);
        while let Some(event) = read_event.next().await {
            println!("Received event: {event:?}");
        }
    }

    Ok(())
}

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<S> UnwindSafe for Socket<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.