pub struct NamedPipeReader { /* private fields */ }
Expand description
A convenience wrapper for reading from Unix named pipes.
Implementations§
Source§impl NamedPipeReader
impl NamedPipeReader
Sourcepub fn from_path(source: &NamedPipePath) -> Self
pub fn from_path(source: &NamedPipePath) -> Self
Creates a new reader, cloning the given NamedPipePath.
Sourcepub fn ensure_pipe_exists(&self) -> Result<&Self>
pub fn ensure_pipe_exists(&self) -> Result<&Self>
Checks if the named pipe actually exists and tries to create it if it doesn’t.
Examples found in repository?
examples/read_print_repeat.rs (line 18)
13fn main() -> io::Result<()> {
14 task::block_on(async {
15 let pipe = NamedPipePath::new("./my_pipe");
16 let reader = pipe.open_read();
17 loop {
18 reader.ensure_pipe_exists().unwrap();
19 println!("Waiting for message...");
20 let next_msg = reader.read_string().await?;
21 println!("Received message: {}", next_msg);
22 }
23 })
24}
Sourcepub async fn read(&self) -> Result<Vec<u8>>
pub async fn read(&self) -> Result<Vec<u8>>
Reads all bytes from the pipe. The returned Future will resolve when something is written to the pipe.
Sourcepub async fn read_string(&self) -> Result<String>
pub async fn read_string(&self) -> Result<String>
Reads a String from the pipe. The returned Future will resolve when something is written to the pipe.
Examples found in repository?
examples/read_print_repeat.rs (line 20)
13fn main() -> io::Result<()> {
14 task::block_on(async {
15 let pipe = NamedPipePath::new("./my_pipe");
16 let reader = pipe.open_read();
17 loop {
18 reader.ensure_pipe_exists().unwrap();
19 println!("Waiting for message...");
20 let next_msg = reader.read_string().await?;
21 println!("Received message: {}", next_msg);
22 }
23 })
24}
More examples
examples/read_write_repeat.rs (line 20)
12fn main() -> io::Result<()> {
13 task::block_on(async move {
14 let pipe = NamedPipePath::new("./reverse_me");
15 let writer = pipe.open_write();
16 let reader = pipe.open_read();
17 loop {
18 pipe.ensure_exists().unwrap();
19 println!("Waiting for message...");
20 let msg = reader.read_string().await?;
21
22 let answer = msg.chars().rev().collect::<String>() + "\n";
23 pipe.ensure_exists().unwrap();
24 println!("Received message, waiting for receiver...");
25 writer.write_str(&answer).await?;
26 }
27 })
28}
Auto Trait Implementations§
impl Freeze for NamedPipeReader
impl RefUnwindSafe for NamedPipeReader
impl Send for NamedPipeReader
impl Sync for NamedPipeReader
impl Unpin for NamedPipeReader
impl UnwindSafe for NamedPipeReader
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