pub struct Socket { /* private fields */ }
Expand description
Helper for blocking communication over the niri socket.
This struct is used to communicate with the niri IPC server. It handles the socket connection and serialization/deserialization of messages.
Implementations§
Source§impl Socket
impl Socket
Sourcepub fn connect() -> Result<Self>
pub fn connect() -> Result<Self>
Connects to the default niri IPC socket.
This is equivalent to calling Self::connect_to
with the path taken from the
SOCKET_PATH_ENV
environment variable.
Sourcepub fn connect_to(path: impl AsRef<Path>) -> Result<Self>
pub fn connect_to(path: impl AsRef<Path>) -> Result<Self>
Connects to the niri IPC socket at the given path.
Sourcepub fn send(&mut self, request: Request) -> Result<Reply>
pub fn send(&mut self, request: Request) -> Result<Reply>
Sends a request to niri and returns the response.
Return values:
Ok(Ok(response))
: successfulResponse
from niriOk(Err(message))
: error message from niriErr(error)
: error communicating with niri
Sourcepub fn read_events(self) -> impl FnMut() -> Result<Event>
pub fn read_events(self) -> impl FnMut() -> Result<Event>
Starts reading event stream Event
s from the socket.
The returned function will block until the next Event
arrives, then return it.
Use this only after requesting an EventStream
.
§Examples
use niri_ipc::{Request, Response};
use niri_ipc::socket::Socket;
fn main() -> std::io::Result<()> {
let mut socket = Socket::connect()?;
let reply = socket.send(Request::EventStream)?;
if matches!(reply, Ok(Response::Handled)) {
let mut read_event = socket.read_events();
while let Ok(event) = read_event() {
println!("Received event: {event:?}");
}
}
Ok(())
}
Auto Trait Implementations§
impl Freeze for Socket
impl RefUnwindSafe for Socket
impl Send for Socket
impl Sync for Socket
impl Unpin for Socket
impl UnwindSafe for Socket
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