Struct OpenOptions
struct OpenOptions { ... }
Options and flags which can be used to configure how a FIFO file is opened.
This builder allows configuring how to create a pipe end from a FIFO file.
Generally speaking, when using OpenOptions, you'll first call new,
then chain calls to methods to set each option, then call either
open_receiver or open_sender, passing the path of the FIFO file you
are trying to open. This will give you a io::Result with a pipe end
inside that you can further operate on.
Examples
Opening a pair of pipe ends from a FIFO file:
use tokio::net::unix::pipe;
# use std::error::Error;
const FIFO_NAME: &str = "path/to/a/fifo";
# async fn dox() -> Result<(), Box<dyn Error>> {
let rx = pipe::OpenOptions::new().open_receiver(FIFO_NAME)?;
let tx = pipe::OpenOptions::new().open_sender(FIFO_NAME)?;
# Ok(())
# }
Opening a Sender on Linux when you are sure the file is a FIFO:
use tokio::net::unix::pipe;
use nix::{unistd::mkfifo, sys::stat::Mode};
# use std::error::Error;
// Our program has exclusive access to this path.
const FIFO_NAME: &str = "path/to/a/new/fifo";
# async fn dox() -> Result<(), Box<dyn Error>> {
mkfifo(FIFO_NAME, Mode::S_IRWXU)?;
let tx = pipe::OpenOptions::new()
.read_write(true)
.unchecked(true)
.open_sender(FIFO_NAME)?;
# Ok(())
# }
Implementations
impl OpenOptions
fn new() -> OpenOptionsCreates a blank new set of options ready for configuration.
All options are initially set to
false.fn read_write(self: &mut Self, value: bool) -> &mut SelfSets the option for read-write access.
This option, when true, will indicate that a FIFO file will be opened in read-write access mode. This operation is not defined by the POSIX standard and is only guaranteed to work on Linux.
Examples
Opening a
Sendereven if there are no open reading ends:use tokio::net::unix::pipe; let tx = pipe::OpenOptions::new() .read_write(true) .open_sender("path/to/a/fifo");Opening a resilient
Receiveri.e. a reading pipe end which will not fail withUnexpectedEofduring reading if all writing ends of the pipe close the FIFO file.use tokio::net::unix::pipe; let tx = pipe::OpenOptions::new() .read_write(true) .open_receiver("path/to/a/fifo");fn unchecked(self: &mut Self, value: bool) -> &mut SelfSets the option to skip the check for FIFO file type.
By default,
open_receiverandopen_senderfunctions will check if the opened file is a FIFO file. Set this option totrueif you are sure the file is a FIFO file.Examples
use tokio::net::unix::pipe; use nix::{unistd::mkfifo, sys::stat::Mode}; # use std::error::Error; // Our program has exclusive access to this path. const FIFO_NAME: &str = "path/to/a/new/fifo"; # async fn dox() -> Result<(), Box<dyn Error>> { mkfifo(FIFO_NAME, Mode::S_IRWXU)?; let rx = pipe::OpenOptions::new() .unchecked(true) .open_receiver(FIFO_NAME)?; # Ok(()) # }fn open_receiver<P: AsRef<Path>>(self: &Self, path: P) -> io::Result<Receiver>Creates a
Receiverfrom a FIFO file with the options specified byself.This function will open the FIFO file at the specified path, possibly check if it is a pipe, and associate the pipe with the default event loop for reading.
Errors
If the file type check fails, this function will fail with
io::ErrorKind::InvalidInput. This function may also fail with other standard OS errors.Panics
This function panics if it is not called from within a runtime with IO enabled.
The runtime is usually set implicitly when this function is called from a future driven by a tokio runtime, otherwise runtime can be set explicitly with
Runtime::enterfunction.fn open_sender<P: AsRef<Path>>(self: &Self, path: P) -> io::Result<Sender>Creates a
Senderfrom a FIFO file with the options specified byself.This function will open the FIFO file at the specified path, possibly check if it is a pipe, and associate the pipe with the default event loop for writing.
Errors
If the file type check fails, this function will fail with
io::ErrorKind::InvalidInput. If the file is not opened in read-write access mode and the file is not currently open for reading, this function will fail withENXIO. This function may also fail with other standard OS errors.Panics
This function panics if it is not called from within a runtime with IO enabled.
The runtime is usually set implicitly when this function is called from a future driven by a tokio runtime, otherwise runtime can be set explicitly with
Runtime::enterfunction.
impl Clone for OpenOptions
fn clone(self: &Self) -> OpenOptions
impl Debug for OpenOptions
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for OpenOptions
fn default() -> OpenOptions
impl Freeze for OpenOptions
impl RefUnwindSafe for OpenOptions
impl Send for OpenOptions
impl Sync for OpenOptions
impl Unpin for OpenOptions
impl UnwindSafe for OpenOptions
impl<T> Any for OpenOptions
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for OpenOptions
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for OpenOptions
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for OpenOptions
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for OpenOptions
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for OpenOptions
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for OpenOptions
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for OpenOptions
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for OpenOptions
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>