pub struct NamedPipeWriter { /* private fields */ }
Expand description
A convenience wrapper for writing to Unix named pipes.
Implementations§
Source§impl NamedPipeWriter
impl NamedPipeWriter
pub fn from_path(source: &NamedPipePath) -> Self
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/write_repeat.rs (line 23)
13fn main() -> io::Result<()> {
14 let text = std::env::args()
15 .nth(1)
16 .unwrap_or_else(|| "Hello world!".to_string())
17 + "\n";
18 println!("Writing String: {}", &text);
19 task::block_on(async move {
20 let pipe = NamedPipePath::new("./my_pipe");
21 let writer = pipe.open_write();
22 loop {
23 writer.ensure_pipe_exists().unwrap();
24 println!("Waiting for receiver...");
25 writer.write_str(&text).await?;
26 }
27 })
28}
Sourcepub async fn write(&self, data: &[u8]) -> Result<()>
pub async fn write(&self, data: &[u8]) -> Result<()>
Writes byte data to the pipe. The returned Future will resolve when the bytes are read from the pipe.
Sourcepub async fn write_str(&self, data: &str) -> Result<()>
pub async fn write_str(&self, data: &str) -> Result<()>
Writes &str data to the pipe. The returned Future will resolve when the string is read from the pipe.
Examples found in repository?
examples/write_repeat.rs (line 25)
13fn main() -> io::Result<()> {
14 let text = std::env::args()
15 .nth(1)
16 .unwrap_or_else(|| "Hello world!".to_string())
17 + "\n";
18 println!("Writing String: {}", &text);
19 task::block_on(async move {
20 let pipe = NamedPipePath::new("./my_pipe");
21 let writer = pipe.open_write();
22 loop {
23 writer.ensure_pipe_exists().unwrap();
24 println!("Waiting for receiver...");
25 writer.write_str(&text).await?;
26 }
27 })
28}
More examples
examples/read_write_repeat.rs (line 25)
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 NamedPipeWriter
impl RefUnwindSafe for NamedPipeWriter
impl Send for NamedPipeWriter
impl Sync for NamedPipeWriter
impl Unpin for NamedPipeWriter
impl UnwindSafe for NamedPipeWriter
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