Skip to content

Commit

Permalink
add module file
Browse files Browse the repository at this point in the history
  • Loading branch information
adjivas committed Oct 22, 2017
1 parent 9e93fb4 commit b93a038
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use std::rc::Rc;
use std::path::PathBuf;
use std::ffi::OsString;
use std::vec;

use syntex_syntax::{ast, ptr};

#[derive(Default, Debug, Clone)]
pub struct Module {
pub list: Vec<ptr::P<ast::Item>>,
pub path: Vec<OsString>,
}

impl From<(Vec<ptr::P<ast::Item>>, PathBuf)> for Module {
fn from((list, mut path): (Vec<ptr::P<ast::Item>>, PathBuf)) -> Module {
path.set_extension("");
Module {
list: list,
path: path.components()
.skip(1)
.map(|comp| comp.as_os_str().to_os_string())
.collect::<Vec<OsString>>(),
}
}
}

impl IntoIterator for Module {
type Item = (ptr::P<ast::Item>, Rc<Vec<OsString>>);
type IntoIter = vec::IntoIter<(ptr::P<ast::Item>, Rc<Vec<OsString>>)>;

fn into_iter(self) -> Self::IntoIter {
let ref rc: Rc<Vec<OsString>> = Rc::new(self.path);
self.list.into_iter()
.map(|item| (item, Rc::clone(rc)))
.collect::<Vec<(ptr::P<ast::Item>, Rc<Vec<OsString>>)>>()
.into_iter()
}
}

0 comments on commit b93a038

Please sign in to comment.