Struct 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&OsStr> for InputPath

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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.
Source§

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T