What I was specifically curious about is why you seem to be against the
usage of the `Str` trait as a bound on the argument to the `captures`
method.


On Tue, May 27, 2014 at 1:01 PM, Kevin Ballard <ke...@sb.org> wrote:

> On May 27, 2014, at 6:05 AM, Benjamin Striegel <ben.strie...@gmail.com>
> wrote:
>
>  > The use of taking <S: Str> is for taking things like &[S], where you
> want to take both &str and String (such as in the other post about
> getops()).
>
> I wouldn't be bothered with leaving the API as-is, but I don't understand
> where this guideline is coming from. Can you elaborate?
>
>
> I don't know if there's any authoritative source for this, but it's been
> suggested in the past for other APIs. The basic issue is that &[String]
> cannot be freely converted to &[&str]; you need to allocate a new Vec for
> that. So if you have a &[String] and try to call an API that takes a
> &[&str] then you're doing extra work just to satisfy the type system. But
> the function in question doesn't actually need &[&str], it just needs a
> slice of things it can convert to &str. So if it takes <S:Str> &[S] then
> you can hand it your &[String] without conversion, or you can hand it a
> &[&str], and it will work with both.
>
> This doesn't necessarily mean you need to use <S: Str> &[S] everywhere.
> But it's a nice thing to do if you think about it.
>
> -Kevin
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to