pub struct NamedPipePath { /* private fields */ }
Expand description
Represents a path to a Unix named pipe (FIFO).
Provides convenience methods to create readers and writers, as well as an easy way to ensure the pipe actually exists.
Implementations§
Source§impl NamedPipePath
impl NamedPipePath
Sourcepub fn new<T: Into<PathBuf>>(path: T) -> Self
pub fn new<T: Into<PathBuf>>(path: T) -> Self
Wraps a given path in a NamedPipePath
.
Examples found in repository?
examples/read_print_repeat.rs (line 15)
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/write_repeat.rs (line 20)
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}
examples/read_write_repeat.rs (line 14)
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}
Sourcepub fn ensure_exists(&self) -> Result<()>
pub fn ensure_exists(&self) -> Result<()>
Ensures the path exists, creating a named pipe in its place if it doesn’t.
Examples found in repository?
examples/read_write_repeat.rs (line 18)
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}
Sourcepub async fn delete(self) -> Result<()>
pub async fn delete(self) -> Result<()>
Tries to delete the pipe from disk and consumes the NamedPipe
.
Sourcepub fn open_read(&self) -> NamedPipeReader
pub fn open_read(&self) -> NamedPipeReader
Creates a reader for this named pipe.
Examples found in repository?
examples/read_print_repeat.rs (line 16)
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 16)
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}
Sourcepub fn open_write(&self) -> NamedPipeWriter
pub fn open_write(&self) -> NamedPipeWriter
Creates a writer for this named pipe.
Examples found in repository?
examples/write_repeat.rs (line 21)
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 15)
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}
Trait Implementations§
Source§impl Clone for NamedPipePath
impl Clone for NamedPipePath
Source§fn clone(&self) -> NamedPipePath
fn clone(&self) -> NamedPipePath
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for NamedPipePath
impl RefUnwindSafe for NamedPipePath
impl Send for NamedPipePath
impl Sync for NamedPipePath
impl Unpin for NamedPipePath
impl UnwindSafe for NamedPipePath
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