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.
12 use std::path::{Path, PathBuf};
13 use session::early_error;
16 #[derive(Clone, Debug)]
17 pub struct SearchPaths {
18 paths: Vec<(PathKind, PathBuf)>,
23 iter: slice::Iter<'a, (PathKind, PathBuf)>,
26 #[derive(Eq, PartialEq, Clone, Copy, Debug)]
37 pub fn new() -> SearchPaths {
38 SearchPaths { paths: Vec::new() }
41 pub fn add_path(&mut self, path: &str, color: errors::ColorConfig) {
42 let (kind, path) = if path.starts_with("native=") {
43 (PathKind::Native, &path["native=".len()..])
44 } else if path.starts_with("crate=") {
45 (PathKind::Crate, &path["crate=".len()..])
46 } else if path.starts_with("dependency=") {
47 (PathKind::Dependency, &path["dependency=".len()..])
48 } else if path.starts_with("framework=") {
49 (PathKind::Framework, &path["framework=".len()..])
50 } else if path.starts_with("all=") {
51 (PathKind::All, &path["all=".len()..])
56 early_error(color, "empty search path given via `-L`");
58 self.paths.push((kind, PathBuf::from(path)));
61 pub fn iter(&self, kind: PathKind) -> Iter {
62 Iter { kind: kind, iter: self.paths.iter() }
66 impl<'a> Iterator for Iter<'a> {
67 type Item = (&'a Path, PathKind);
69 fn next(&mut self) -> Option<(&'a Path, PathKind)> {
71 match self.iter.next() {
72 Some(&(kind, ref p)) if self.kind == PathKind::All ||
73 kind == PathKind::All ||
74 kind == self.kind => {
75 return Some((p, kind))