Struct holochain::prelude::dependencies::kitsune_p2p_types::dependencies::lair_keystore_api::dependencies::tokio::net::unix::pipe::OpenOptions
source · 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 RefUnwindSafe for OpenOptions
impl Send for OpenOptions
impl Sync for OpenOptions
impl Unpin for OpenOptions
impl UnwindSafe for OpenOptions
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
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
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> 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> ⓘ
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.