pub struct OpenOptions { /* private fields */ }
Expand description
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;
const FIFO_NAME: &str = "path/to/a/fifo";
let rx = pipe::OpenOptions::new().open_receiver(FIFO_NAME)?;
let tx = pipe::OpenOptions::new().open_sender(FIFO_NAME)?;
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};
// Our program has exclusive access to this path.
const FIFO_NAME: &str = "path/to/a/new/fifo";
mkfifo(FIFO_NAME, Mode::S_IRWXU)?;
let tx = pipe::OpenOptions::new()
.read_write(true)
.unchecked(true)
.open_sender(FIFO_NAME)?;
Implementations§
Source§impl OpenOptions
impl OpenOptions
Sourcepub fn new() -> OpenOptions
pub fn new() -> OpenOptions
Creates a blank new set of options ready for configuration.
All options are initially set to false
.
Sourcepub fn read_write(&mut self, value: bool) -> &mut OpenOptions
pub fn read_write(&mut self, value: bool) -> &mut OpenOptions
Sets 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 Sender
even 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 Receiver
i.e. a reading pipe end which will not
fail with UnexpectedEof
during 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");
Sourcepub fn unchecked(&mut self, value: bool) -> &mut OpenOptions
pub fn unchecked(&mut self, value: bool) -> &mut OpenOptions
Sets the option to skip the check for FIFO file type.
By default, open_receiver
and open_sender
functions will check
if the opened file is a FIFO file. Set this option to true
if you are
sure the file is a FIFO file.
§Examples
use tokio::net::unix::pipe;
use nix::{unistd::mkfifo, sys::stat::Mode};
// Our program has exclusive access to this path.
const FIFO_NAME: &str = "path/to/a/new/fifo";
mkfifo(FIFO_NAME, Mode::S_IRWXU)?;
let rx = pipe::OpenOptions::new()
.unchecked(true)
.open_receiver(FIFO_NAME)?;
Sourcepub fn open_receiver<P>(&self, path: P) -> Result<Receiver, Error>
pub fn open_receiver<P>(&self, path: P) -> Result<Receiver, Error>
Creates a Receiver
from a FIFO file with the options specified by self
.
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::enter
function.
Sourcepub fn open_sender<P>(&self, path: P) -> Result<Sender, Error>
pub fn open_sender<P>(&self, path: P) -> Result<Sender, Error>
Creates a Sender
from a FIFO file with the options specified by self
.
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 with ENXIO
.
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::enter
function.
Trait Implementations§
Source§impl Clone for OpenOptions
impl Clone for OpenOptions
Source§fn clone(&self) -> OpenOptions
fn clone(&self) -> OpenOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for OpenOptions
impl Debug for OpenOptions
Source§impl Default for OpenOptions
impl Default for OpenOptions
Source§fn default() -> OpenOptions
fn default() -> OpenOptions
Auto Trait Implementations§
impl Freeze for OpenOptions
impl RefUnwindSafe for OpenOptions
impl Send for OpenOptions
impl Sync for OpenOptions
impl Unpin for OpenOptions
impl UnwindSafe for OpenOptions
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);