Great, thanks Patrick + Huon

On Sun, Mar 23, 2014 at 7:47 AM, Huon Wilson <[email protected]> wrote:

> On 23/03/14 18:14, Patrick Walton wrote:
>
>> On 3/23/14 12:11 AM, Phil Dawes wrote:
>>
>>> On Sun, Mar 23, 2014 at 2:04 AM, Patrick Walton <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>>     Why not change the signature of `search_crate` to take `~str`?
>>>
>>>     Patrick
>>>
>>>
>>> Hi Patrick,
>>>
>>> The main reason I haven't done this is that it is already used from a
>>> bunch of places where a path is &[&str] as the result of an earlier
>>> split_str("::")
>>> e.g.
>>>         let path : ~[&str] = s.split_str("::").collect();
>>>         ...
>>>         search_crate(path);
>>>
>>
>> Ah, I see. Well, in that case you can make a trait (say, `String`), which
>> implements a method `.as_str()` that returns an `&str`, and have that trait
>> implemented by both `&str` and `~str`. (IIRC the standard library may have
>> such a trait already, for `Path`?)
>>
>> You can then write:
>>
>>     fn search_crate<T:String>(x: &[T]) {
>>         ...
>>         for string in x.iter() {
>>             ... string.as_str() ...
>>         }
>>     }
>>
>> And the function will be callable with both `&str` and `~str`. Again, I
>> think the standard library has such a trait implemented already, for this
>> use case.
>>
>> Patrick
>>
>> _______________________________________________
>> Rust-dev mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>
> std::str::Str http://static.rust-lang.org/doc/master/std/str/trait.Str.
> html
>
>
> Huon
>
> _______________________________________________
> 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

Reply via email to