How is that any better than just using strings? ["a", "b", "c"] is no more typing than ['a', 'b', 'c'], but it doesn't require defining new traits.
-Kevin On May 26, 2014, at 4:54 PM, Sean McArthur <[email protected]> wrote: > Considering many options would be single characters, it'd seem nice to also > be able to pass a slice of chars. It doesn't look like char implements Str. > getopts could define a new trait, Text or something, for all 3... > > > On Mon, May 26, 2014 at 2:56 PM, Kevin Ballard <[email protected]> wrote: > I think getopts has an old API. All the methods that take &[String] should > probably be rewritten to be generic with <S: Str> and take &[S] instead, > which will allow taking either a slice of Strings or a slice of &str's. > > -Kevin > > On May 26, 2014, at 12:16 PM, Benjamin Striegel <[email protected]> > wrote: > >> I'm not familiar with the getopts module, but on the surface that behavior >> sounds wrong to me. >> >> As for the verbosity of the repeated `to_owned` calls, this sounds like the >> perfect application for macros: >> >> #![feature(macro_rules)] >> >> macro_rules! owned( >> ($($e:expr),*) => ([$($e.to_owned()),*]) >> ) >> >> fn main() { >> let x = owned!["b", "c", "d"]; >> } >> >> >> On Mon, May 26, 2014 at 2:11 PM, Gulshan Singh <[email protected]> wrote: >> Why does getopts::Matches::opts_present() take an array of heap allocated >> strings? Unless I'm missing something, it doesn't seem like it needs to: >> https://github.com/mozilla/rust/blob/7d76d0ad44e1ec203d235f22eb3514247b8cbfe5/src/libgetopts/lib.rs#L302 >> >> Currently, my code to use it looks like this: >> >> if matches.opts_present(["b".to_owned(), "x".to_owned(), "s".to_owned(), >> "w".to_owned()]) { /* */ } >> >> 1. Should the function be converted to take a list of borrowed strings? >> 2. Regardless of what this function should take as an argument, is the way >> I'm constructing a list of StrBufs the correct way to do it? It seems a bit >> verbose. >> >> _______________________________________________ >> Rust-dev mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/rust-dev >> >> >> _______________________________________________ >> Rust-dev mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/rust-dev > > > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev > >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
