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.
13 #[derive(Clone, Show)]
14 pub struct SearchPaths {
15 paths: Vec<(PathKind, Path)>,
20 iter: slice::Iter<'a, (PathKind, Path)>,
23 #[derive(Eq, PartialEq, Clone, Copy, Show)]
33 pub fn new() -> SearchPaths {
34 SearchPaths { paths: Vec::new() }
37 pub fn add_path(&mut self, path: &str) {
38 let (kind, path) = if path.starts_with("native=") {
39 (PathKind::Native, path.slice_from("native=".len()))
40 } else if path.starts_with("crate=") {
41 (PathKind::Crate, path.slice_from("crate=".len()))
42 } else if path.starts_with("dependency=") {
43 (PathKind::Dependency, path.slice_from("dependency=".len()))
44 } else if path.starts_with("all=") {
45 (PathKind::All, path.slice_from("all=".len()))
49 self.paths.push((kind, Path::new(path)));
52 pub fn iter(&self, kind: PathKind) -> Iter {
53 Iter { kind: kind, iter: self.paths.iter() }
57 impl<'a> Iterator for Iter<'a> {
58 type Item = (&'a Path, PathKind);
60 fn next(&mut self) -> Option<(&'a Path, PathKind)> {
62 match self.iter.next() {
63 Some(&(kind, ref p)) if self.kind == PathKind::All ||
64 kind == PathKind::All ||
65 kind == self.kind => {
66 return Some((p, kind))