pub struct Socket<S> { /* private fields */ }Implementations§
Source§impl<S: SocketStream> Socket<S>
impl<S: SocketStream> Socket<S>
Sourcepub async fn connect() -> Result<Self, Error>
pub async fn connect() -> Result<Self, Error>
Connects to the default niri IPC socket.
This is the async version of Socket::connect
Sourcepub async fn connect_to(path: impl AsRef<Path>) -> Result<Self, Error>
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
Sourcepub async fn send(&mut self, request: Request) -> Result<Reply, Error>
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
Sourcepub async fn into_event_stream(
self,
) -> Result<impl Stream<Item = Result<Event, Error>>, IntoEventStreamError>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more