pub enum SizedOutput {
    Stdout(Stdout),
    Pipe(OsStringFile),
    File(OsStringFile),
}
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(OsStringFile)

a File represeinting the named pipe e.g. crated with mkfifo

File(OsStringFile)

a normal File opened from the path

Implementations

Contructs a new output either by opening/creating the file or for ‘-’ returning stdout

Contructs a new output to stdout

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.

set the length of the file, either using File::set_len or as the content-length header of the http put

convert to an normal Output without setting the length

convert to an normal Output setting the length of the file to size if it is Some

The original path used to create this SizedOutput

Trait Implementations

Formats the value using the given formatter. Read more

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

formats as the path it was created from

Formats the value using the given formatter. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.