1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 pub struct SearchPaths {
15 paths: Vec<(PathKind, Path)>,
20 iter: slice::Iter<'a, (PathKind, Path)>,
23 #[deriving(Eq, PartialEq, Clone, Copy)]
32 pub fn new() -> SearchPaths {
33 SearchPaths { paths: Vec::new() }
36 pub fn add_path(&mut self, path: &str) {
37 let (kind, path) = if path.starts_with("native=") {
38 (PathKind::Native, path.slice_from("native=".len()))
39 } else if path.starts_with("crate=") {
40 (PathKind::Crate, path.slice_from("crate=".len()))
41 } else if path.starts_with("dependency=") {
42 (PathKind::Dependency, path.slice_from("dependency=".len()))
43 } else if path.starts_with("all=") {
44 (PathKind::All, path.slice_from("all=".len()))
48 self.paths.push((kind, Path::new(path)));
51 pub fn iter(&self, kind: PathKind) -> Iter {
52 Iter { kind: kind, iter: self.paths.iter() }
56 impl<'a> Iterator for Iter<'a> {
59 fn next(&mut self) -> Option<&'a Path> {
61 match self.iter.next() {
62 Some(&(kind, ref p)) if self.kind == PathKind::All ||
63 kind == PathKind::All ||
64 kind == self.kind => return Some(p),