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

source

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§

source§

impl Debug for Pipes

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.