pub enum OpenFile {
Stdin(Stdin),
Stdout(Stdout),
Stderr(Stderr),
File(Arc<File>),
PipeReader(Arc<PipeReader>),
PipeWriter(Arc<PipeWriter>),
Stream(Box<dyn Stream>),
}Expand description
Represents a file open in a shell context.
File- and pipe-backed variants hold their handle behind an Arc, so
cloning an OpenFile shares the underlying descriptor by reference count.
The shell opens a fresh context for each subshell, command substitution,
background job, and function call and runs them as in-process tasks against
one process-wide descriptor table (rather than via fork(2) like a
traditional shell); sharing the descriptor keeps deeply nested or highly
concurrent execution from exhausting that table. A descriptor is duplicated
for real only when an independently owned copy is needed to hand to an
external child process — see OpenFile::try_clone_to_owned and
the Stdio conversion below.
Variants§
Stdin(Stdin)
The original standard input this process was started with.
Stdout(Stdout)
The original standard output this process was started with.
Stderr(Stderr)
The original standard error this process was started with.
File(Arc<File>)
A file open for reading or writing.
PipeReader(Arc<PipeReader>)
A read end of a pipe.
PipeWriter(Arc<PipeWriter>)
A write end of a pipe.
Stream(Box<dyn Stream>)
A custom stream.
Implementations§
Source§impl OpenFile
impl OpenFile
Sourcepub fn try_borrow_as_fd(&self) -> Result<BorrowedFd<'_>, Error>
Available on Unix only.
pub fn try_borrow_as_fd(&self) -> Result<BorrowedFd<'_>, Error>
Borrows the open file as a BorrowedFd.
§Errors
Returns an error if the operation is not supported for the underlying file type.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Checks if the open file is associated with a terminal.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for OpenFile
Available on crate feature serde only.
impl<'de> Deserialize<'de> for OpenFile
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<PipeReader> for OpenFile
impl From<PipeReader> for OpenFile
Source§fn from(reader: PipeReader) -> Self
fn from(reader: PipeReader) -> Self
Source§impl From<PipeWriter> for OpenFile
impl From<PipeWriter> for OpenFile
Source§fn from(writer: PipeWriter) -> Self
fn from(writer: PipeWriter) -> Self
Source§impl Read for OpenFile
impl Read for OpenFile
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl Write for OpenFile
impl Write for OpenFile
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl !RefUnwindSafe for OpenFile
impl !UnwindSafe for OpenFile
impl Freeze for OpenFile
impl Send for OpenFile
impl Sync for OpenFile
impl Unpin for OpenFile
impl UnsafeUnpin for OpenFile
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more