On 3/22/14 2:53 PM, Phil Dawes wrote:
Hello!,

I'm learning rust and finding myself fighting the language a little and
so I could do with a bit of help.

In my code completion project I have a function which parses 'use' view
items (using libsyntax) and currently returns a vector of vectors of
strings representing fully qualified paths (e.g. std::foo::bar).
I also have a function which traverses crates and resolves a path to an
item source position. It takes the path as a reference to a slice of
string references. Here's a stubbed out illustration of the code:

pub fn parse_view_item() -> Vec<Vec<~str>> {
     // stub code:
     let mut vv = Vec::new();
     let mut v = Vec::new();
     v.push(~"std");
     v.push(~"foo");
     v.push(~"bar");
     vv.push(v);
     return vv
}

pub fn search_crate(path : &[&str]) {
     // ...
}

fn main() {
     let paths = parse_view_item();

     for path in paths.iter() {
         // translate Vec<~str> to Vec<&str>
         let mut v2 = Vec::new();
         for item in path.iter() {
             v2.push(item.as_slice());
         }
         search_crate(v2.as_slice());
     }
}

Why not change the signature of `search_crate` to take `~str`?

Patrick

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to