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
impl CliInterpreter
Sourcepub fn init(args: Vec<String>) -> Self
pub fn init(args: Vec<String>) -> Self
Creates a new interpreter from a list of argument strings.
Sourcepub fn find_argument(&self, name: &str) -> Option<usize>
pub fn find_argument(&self, name: &str) -> Option<usize>
Searches for name (e.g. "-o") and returns its index, or None.
Sourcepub fn get_next_value(&mut self, index: usize) -> Result<&str>
pub fn get_next_value(&mut self, index: usize) -> Result<&str>
Returns the value immediately following the argument at index,
marking both as consumed.
Sourcepub fn release_argument(&mut self, index: usize)
pub fn release_argument(&mut self, index: usize)
Marks the argument at index as consumed.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Returns true when every argument has been consumed.
Sourcepub fn first_unconsumed(&self) -> Option<&str>
pub fn first_unconsumed(&self) -> Option<&str>
Returns the first un-consumed argument, if any.
Sourcepub fn reinterpret_i32(&mut self, index: usize) -> Result<i32>
pub fn reinterpret_i32(&mut self, index: usize) -> Result<i32>
Parses the value at index + 1 as i32.
Sourcepub fn reinterpret_u32(&mut self, index: usize) -> Result<u32>
pub fn reinterpret_u32(&mut self, index: usize) -> Result<u32>
Parses the value at index + 1 as u32.
Sourcepub fn reinterpret_f32(&mut self, index: usize) -> Result<f32>
pub fn reinterpret_f32(&mut self, index: usize) -> Result<f32>
Parses the value at index + 1 as f32.
Sourcepub fn reinterpret_bool(&mut self, index: usize) -> Result<bool>
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).
Sourcepub fn reinterpret_string(&mut self, index: usize) -> Result<String>
pub fn reinterpret_string(&mut self, index: usize) -> Result<String>
Returns the value at index + 1 as a String.
Auto Trait Implementations§
impl Freeze for CliInterpreter
impl RefUnwindSafe for CliInterpreter
impl Send for CliInterpreter
impl Sync for CliInterpreter
impl Unpin for CliInterpreter
impl UnsafeUnpin for CliInterpreter
impl UnwindSafe for CliInterpreter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more