getargs-os 0.1.1

Provides a way for `getargs` to parse OS strings
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented0 out of 2 items with examples
  • Size
  • Source code size: 16.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.15 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • LoganDark/getargs-os
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • LoganDark

getargs-os

Adds a newtype wrapper (OsArgument) around OsStr that allows it to be parsed by getargs::Options.

In combination with the argv crate, this allows for lowest-cost argument parsing across all platforms (zero-cost on Linux).

This is a separate crate from getargs because it requires (wildly) unsafe code. std does not want us messing with OsStrs at all!

Usage

First, obtain an iterator over OsStrs somehow - I recommend argv once again - then wrap them in OsArgument and pass that to Options::new.

use getargs::Options;
use getargs_os::OsArgument;
let mut opts = Options::new(argv::iter().skip(1).map(<&OsArgument>::from));

Then use Optionsgetargs::Options as normal - check its documentation for more usage examples.

You can use the os! macro to create new OS strings to compare arguments against. This macro works on all operating systems. For example:

while let Some(arg) = opts.next_arg().expect("some ooga booga just happened") {
	if arg == Arg::Long(os!("help")) {
		// print help...
	} else {
		// ...
	}
}