j-tai / getargs Goto Github PK
View Code? Open in Web Editor NEWA truly zero-cost argument parser for Rust
License: MIT License
A truly zero-cost argument parser for Rust
License: MIT License
The argv
crate provides a zero-alloc way to get the process arguments. It would be really cool if I could use this with getargs
without having to put the arguments in a Vec
. Is this a use case you'd be willing to support?
(Side note: argv
also returns &OsStr
, not &str
, so it's non-UTF-8 - I would have assumed getargs
would work with that, but I'm not sure)
I think your next
implementation has unintentional lifetime elision where self
is borrowed for the duration of 'a
.
error[E0597]: `options` does not live long enough
--> src/settings.rs:123:24
|
123 | while let Some(opt) = options.next() {
| ^^^^^^^^^^^^^^
| |
| borrowed value does not live long enough
| argument requires that `options` is borrowed for `'static`
...
144 | }
| - `options` dropped here while still borrowed
The reason why rustc thinks options
has to be borrowed for 'static
is because of this inner match:
if let getargs::Error::DoesNotRequireValue(opt) = err {
match opt {
Opt::Short(short) => Error::DoesNotRequireValueShort(short),
Opt::Long(long) => Error::DoesNotRequireValueLong(long)
}
}
and my Error
enum declaration says:
DoesNotRequireValueLong(&'static str)
The strings being used with Options
are 'static
, so I would've expected this to work. Is there any reason why it shouldn't, or is this a mistake?
For now I can get around this with a transmute
, but that is incredibly unsafe and this could probably be fixed by adjusting lifetimes a bit.
Thought I'd open this issue to track the days till 0.5.0's release. :)
Hopefully it's coming out soon!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.