Skip to main content

CliInterpreter

Struct CliInterpreter 

Source
pub struct CliInterpreter { /* private fields */ }
Expand description

A simple command-line argument interpreter.

Arguments are stored alongside a “consumed” flag so that callers can verify every argument has been handled.

Implementations§

Source§

impl CliInterpreter

Source

pub fn init(args: Vec<String>) -> Self

Creates a new interpreter from a list of argument strings.

Source

pub fn find_argument(&self, name: &str) -> Option<usize>

Searches for name (e.g. "-o") and returns its index, or None.

Source

pub fn get_next_value(&mut self, index: usize) -> Result<&str>

Returns the value immediately following the argument at index, marking both as consumed.

Source

pub fn release_argument(&mut self, index: usize)

Marks the argument at index as consumed.

Source

pub fn is_exhausted(&self) -> bool

Returns true when every argument has been consumed.

Source

pub fn first_unconsumed(&self) -> Option<&str>

Returns the first un-consumed argument, if any.

Source

pub fn reinterpret_i32(&mut self, index: usize) -> Result<i32>

Parses the value at index + 1 as i32.

Source

pub fn reinterpret_u32(&mut self, index: usize) -> Result<u32>

Parses the value at index + 1 as u32.

Source

pub fn reinterpret_f32(&mut self, index: usize) -> Result<f32>

Parses the value at index + 1 as f32.

Source

pub fn reinterpret_bool(&mut self, index: usize) -> Result<bool>

Parses the value at index + 1 as bool (accepts true/false, 1/0, yes/no).

Source

pub fn reinterpret_string(&mut self, index: usize) -> Result<String>

Returns the value at index + 1 as a String.

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