Struct async_pipes::Pipes
source · pub struct Pipes { /* private fields */ }
Expand description
Provided by Pipeline::from_pipes, used to create the I/O objects for each end of a pipe.
Examples
Create three pipes and demonstrate how to acquire the I/O objects of a pipe by name.
use async_pipes::{Pipeline, PipeReader, Pipes, PipeWriter};
// `pipes` is mutable so it can give ownership of values to the I/O objects produced in `Pipes::create_io`
let (_pipeline, mut pipes): (Pipeline, Pipes) = Pipeline::from_pipes(vec!["a", "b", "c"]);
let pipe_io = pipes.create_io::<String>("a");
assert!(pipe_io.is_some());
// A tuple is returned containing the I/O objects
let (w, r): (PipeWriter<String>, PipeReader<String>) = pipe_io.unwrap();
// `None` is returned if the pipe name doesn't exist
assert!(pipes.create_io::<String>("d").is_none());
Implementations§
source§impl Pipes
impl Pipes
sourcepub fn create_io<T>(
&mut self,
name: impl AsRef<str>
) -> Option<(PipeWriter<T>, PipeReader<T>)>
pub fn create_io<T>( &mut self, name: impl AsRef<str> ) -> Option<(PipeWriter<T>, PipeReader<T>)>
Creates the I/O objects associated with a pipe identified by the provided name.
If a pipe with the name exists, a tuple with the I/O objects is returned; otherwise, None is returned.
If the pipe with that name exists, ownership is transferred to the created I/O objects. This means that a later call with the same name will result in None, preventing multiple I/O objects from being created. This is necessary to properly track all data in the pipes.
Examples
See Pipes for examples.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Pipes
impl Send for Pipes
impl Sync for Pipes
impl Unpin for Pipes
impl UnwindSafe for Pipes
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