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, config};
15 #[derive(Clone, Debug)]
16 pub struct SearchPaths {
17 paths: Vec<(PathKind, PathBuf)>,
22 iter: slice::Iter<'a, (PathKind, PathBuf)>,
25 #[derive(Eq, PartialEq, Clone, Copy, Debug)]
36 pub fn new() -> SearchPaths {
37 SearchPaths { paths: Vec::new() }
40 pub fn add_path(&mut self, path: &str, output: config::ErrorOutputType) {
41 let (kind, path) = if path.starts_with("native=") {
42 (PathKind::Native, &path["native=".len()..])
43 } else if path.starts_with("crate=") {
44 (PathKind::Crate, &path["crate=".len()..])
45 } else if path.starts_with("dependency=") {
46 (PathKind::Dependency, &path["dependency=".len()..])
47 } else if path.starts_with("framework=") {
48 (PathKind::Framework, &path["framework=".len()..])
49 } else if path.starts_with("all=") {
50 (PathKind::All, &path["all=".len()..])
55 early_error(output, "empty search path given via `-L`");
57 self.paths.push((kind, PathBuf::from(path)));
60 pub fn iter(&self, kind: PathKind) -> Iter {
61 Iter { kind: kind, iter: self.paths.iter() }
65 impl<'a> Iterator for Iter<'a> {
66 type Item = (&'a Path, PathKind);
68 fn next(&mut self) -> Option<(&'a Path, PathKind)> {
70 match self.iter.next() {
71 Some(&(kind, ref p)) if self.kind == PathKind::All ||
72 kind == PathKind::All ||
73 kind == self.kind => {
74 return Some((p, kind))