Struct clio::OutputPath
source · pub struct OutputPath { /* private fields */ }
Expand description
A builder for Output that validates the path but defers creating it until you call the create method.
The create_with_len allows setting the size before writing. This is mostly useful 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::OutputPath;
#[derive(Parser)]
struct Opt {
/// path to file, use '-' for stdout
#[clap(value_parser)]
output_file: OutputPath,
}
Implementations§
source§impl OutputPath
impl OutputPath
sourcepub fn new<S: TryInto<ClioPath>>(path: S) -> Result<Self>where
Error: From<<S as TryInto<ClioPath>>::Error>,
pub fn new<S: TryInto<ClioPath>>(path: S) -> Result<Self>where Error: From<<S as TryInto<ClioPath>>::Error>,
Construct a new OutputPath
from an string
It checks if an output file could plausibly be created at that path
sourcepub fn std() -> Self
pub fn std() -> Self
Constructs a new OutputPath
of "-"
for stdout
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 create_with_len(self, size: u64) -> Result<Output>
pub fn create_with_len(self, size: u64) -> Result<Output>
Create the file with a predetermined length, either using File::set_len
or as the content-length
header of the http put
sourcepub fn path(&self) -> &ClioPath
pub fn path(&self) -> &ClioPath
The original path represented by this OutputPath
sourcepub fn is_local(&self) -> bool
pub fn is_local(&self) -> bool
Returns true if this Output
is on the local file system,
as opposed to point to stout or a URL
sourcepub fn can_seek(&self) -> bool
pub fn can_seek(&self) -> bool
Returns true
if this OutputPath
points to a file,
and false
if this OutputPath
is std out or points to a pipe.
Note that the file is not opened yet, so there are possible when you
open the file it might have changed.
Trait Implementations§
source§impl Clone for OutputPath
impl Clone for OutputPath
source§fn clone(&self) -> OutputPath
fn clone(&self) -> OutputPath
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for OutputPath
impl Debug for OutputPath
source§impl Default for OutputPath
impl Default for OutputPath
source§impl Display for OutputPath
impl Display for OutputPath
formats as the path it was created from
source§impl PartialEq<OutputPath> for OutputPath
impl PartialEq<OutputPath> for OutputPath
source§fn eq(&self, other: &OutputPath) -> bool
fn eq(&self, other: &OutputPath) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl TryFrom<&OsStr> for OutputPath
impl TryFrom<&OsStr> for OutputPath
source§impl TryFrom<&OsString> for OutputPath
impl TryFrom<&OsString> for OutputPath
source§impl TryFrom<&Path> for OutputPath
impl TryFrom<&Path> for OutputPath
source§impl TryFrom<&PathBuf> for OutputPath
impl TryFrom<&PathBuf> for OutputPath
source§impl TryFrom<&String> for OutputPath
impl TryFrom<&String> for OutputPath
source§impl TryFrom<&str> for OutputPath
impl TryFrom<&str> for OutputPath
source§impl TryFrom<ClioPath> for OutputPath
impl TryFrom<ClioPath> for OutputPath
source§impl ValueParserFactory for OutputPath
Available on crate feature clap-parse
only.
impl ValueParserFactory for OutputPath
clap-parse
only.§type Parser = OsStrParser<OutputPath>
type Parser = OsStrParser<OutputPath>
ValueParser
]. Read moresource§fn value_parser() -> Self::Parser
fn value_parser() -> Self::Parser
Self::Parser
]