Struct clio::InputPath

source ·
pub struct InputPath { /* private fields */ }
Expand description

A builder for Input that validates the path but defers creating it until you call the open method.

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::InputPath;

#[derive(Parser)]
struct Opt {
    /// path to file, use '-' for stdin
    #[clap(value_parser)]
    input_file: InputPath,
}

Implementations§

source§

impl InputPath

source

pub fn new<S: TryInto<ClioPath>>(path: S) -> Result<Self>
where Error: From<<S as TryInto<ClioPath>>::Error>,

Constructs a new InputPath representing the path and checking that the file exists and is readable

note: even if this passes open may still fail if e.g. the file was delete in between

source

pub fn std() -> Self

Constructs a new InputPath to stdout (“-”)

source

pub fn is_std(&self) -> bool

Returns true if this InputPath is stdin

source

pub fn is_tty(&self) -> bool

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

source

pub fn is_local(&self) -> bool

Returns true if this InputPath is on the local file system, as opposed to point to stdin or a URL

source

pub fn open(self) -> Result<Input>

Create an Input by opening the file or for ‘-’ returning stdin.

This is unlikely to error as the path is checked when the InputPath was created by new but time of use/time of check means that things could have changed in-between e.g. the file could have been deleted.

source

pub fn path(&self) -> &ClioPath

The original path used to create this InputPath

Trait Implementations§

source§

impl Clone for InputPath

source§

fn clone(&self) -> InputPath

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 InputPath

source§

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

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

impl Default for InputPath

source§

fn default() -> Self

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

impl Display for InputPath

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 InputPath

source§

fn eq(&self, other: &InputPath) -> 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 InputPath

§

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 InputPath

§

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 InputPath

§

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 InputPath

§

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 InputPath

§

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 InputPath

§

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 InputPath

§

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 InputPath

Available on crate feature clap-parse only.
§

type Parser = OsStrParser<InputPath>

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

fn value_parser() -> Self::Parser

Create the specified [Self::Parser]
source§

impl Eq for InputPath

source§

impl StructuralEq for InputPath

source§

impl StructuralPartialEq for InputPath

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.