]> git.lizzy.rs Git - rust.git/blob - src/librustc/session/search_paths.rs
doc: remove incomplete sentence
[rust.git] / src / librustc / session / search_paths.rs
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.
4 //
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.
10
11 use std::slice;
12
13 #[deriving(Clone)]
14 pub struct SearchPaths {
15     paths: Vec<(PathKind, Path)>,
16 }
17
18 pub struct Iter<'a> {
19     kind: PathKind,
20     iter: slice::Iter<'a, (PathKind, Path)>,
21 }
22
23 #[deriving(Eq, PartialEq, Clone, Copy)]
24 pub enum PathKind {
25     Native,
26     Crate,
27     Dependency,
28     All,
29 }
30
31 impl SearchPaths {
32     pub fn new() -> SearchPaths {
33         SearchPaths { paths: Vec::new() }
34     }
35
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()))
45         } else {
46             (PathKind::All, path)
47         };
48         self.paths.push((kind, Path::new(path)));
49     }
50
51     pub fn iter(&self, kind: PathKind) -> Iter {
52         Iter { kind: kind, iter: self.paths.iter() }
53     }
54 }
55
56 impl<'a> Iterator for Iter<'a> {
57     type Item = &'a Path;
58
59     fn next(&mut self) -> Option<&'a Path> {
60         loop {
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),
65                 Some(..) => {}
66                 None => return None,
67             }
68         }
69     }
70 }