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

source

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

source

pub fn std() -> Self

Constructs a new OutputPath of "-" for stdout

source

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

source

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

source

pub fn create(self) -> Result<Output>

Create an Output without setting the length

source

pub fn path(&self) -> &ClioPath

The original path represented by this OutputPath

source

pub fn is_std(&self) -> bool

Returns true if this Output is stdout

source

pub fn is_tty(&self) -> bool

Returns true if this is stdout and it is connected to a tty

source

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

source

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

source§

fn clone(&self) -> OutputPath

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OutputPath

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for OutputPath

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for OutputPath

formats as the path it was created from

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for OutputPath

source§

fn eq(&self, other: &OutputPath) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<&OsStr> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: &OsStr) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&OsString> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: &OsString) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&Path> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: &Path) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&PathBuf> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: &PathBuf) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&String> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: &String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&str> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: &str) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<ClioPath> for OutputPath

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(file_name: ClioPath) -> Result<Self>

Performs the conversion.
source§

impl ValueParserFactory for OutputPath

Available on crate feature clap-parse only.
§

type Parser = OsStrParser<OutputPath>

Generated parser, usually [ValueParser]. Read more
source§

fn value_parser() -> Self::Parser

Create the specified [Self::Parser]
source§

impl Eq for OutputPath

source§

impl StructuralEq for OutputPath

source§

impl StructuralPartialEq for OutputPath

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.