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 <ke...@sb.org> 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 <ben.strie...@gmail.com>
> 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 <gsingh_2...@yahoo.com>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
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to