Enum clio::SizedOutput
source · [−]Expand description
A builder for Output that allows setting the size before writing. This is mostly usefull with the “http” feature for setting the Content-Length header
It is designed to be used with the clap
crate when taking a file name as an
argument to CLI app
use clap::Parser;
use clio::SizedOutput;
#[derive(Parser)]
struct Opt {
/// path to file, use '-' for stdout
#[clap(value_parser)]
output_file: SizedOutput,
}
Variants
Stdout(Stdout)
a Stdout
when the path was -
Pipe(OsString, File)
a File
represeinting the named pipe e.g. crated with mkfifo
File(OsString, File)
a normal File
opened from the path
Implementations
sourceimpl SizedOutput
impl SizedOutput
sourcepub fn new<S: AsRef<OsStr>>(path: S) -> Result<Self>
pub fn new<S: AsRef<OsStr>>(path: S) -> Result<Self>
Contructs a new output either by opening/creating the file or for ‘-’ returning stdout
sourcepub fn try_from_os_str(path: &OsStr) -> Result<Self, OsString>
pub fn try_from_os_str(path: &OsStr) -> Result<Self, OsString>
Contructs a new SizedOutput
either by opening/creating the file or for ‘-’ returning stdout
The error is converted to a OsString
so that stuctopt can show it to the user.
It is recomended that you use TryFrom::try_from
and clap 3.0 instead.
sourcepub fn with_len(self, size: u64) -> Result<Output>
pub fn with_len(self, size: u64) -> Result<Output>
set the length of the file, either using File::set_len
or as the content-length header of the http put
sourcepub fn without_len(self) -> Result<Output>
pub fn without_len(self) -> Result<Output>
convert to an normal Output
without setting the length
sourcepub fn maybe_with_len(self, size: Option<u64>) -> Result<Output>
pub fn maybe_with_len(self, size: Option<u64>) -> Result<Output>
convert to an normal Output
setting the length of the file to size if it is Some
sourcepub fn path(&self) -> &OsStr
pub fn path(&self) -> &OsStr
The original path used to create this SizedOutput
Trait Implementations
sourceimpl Debug for SizedOutput
impl Debug for SizedOutput
sourceimpl Default for SizedOutput
impl Default for SizedOutput
sourceimpl Display for SizedOutput
impl Display for SizedOutput
formats as the path it was created from
Auto Trait Implementations
impl RefUnwindSafe for SizedOutput
impl Send for SizedOutput
impl Sync for SizedOutput
impl Unpin for SizedOutput
impl UnwindSafe for SizedOutput
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more