summaryrefslogtreecommitdiff
path: root/dhall_syntax/src/core/import.rs
diff options
context:
space:
mode:
authorFintan Halpenny2019-09-02 21:17:00 +0100
committerFintan Halpenny2019-09-02 21:17:00 +0100
commite73f822b6972e8fa2e72b56ff5378b91bea1a5e6 (patch)
tree853d36295b3a705d9143e0feb72855f900237de0 /dhall_syntax/src/core/import.rs
parent4a86274878d5ab0ef4f9d8597606226adfd048de (diff)
Remove the notion of Directory and have File be the vector of components
Diffstat (limited to '')
-rw-r--r--dhall_syntax/src/core/import.rs49
1 files changed, 13 insertions, 36 deletions
diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs
index 82bb7ff..4aad70d 100644
--- a/dhall_syntax/src/core/import.rs
+++ b/dhall_syntax/src/core/import.rs
@@ -12,23 +12,8 @@ pub enum FilePrefix {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct Directory {
- pub components: Vec<String>,
-}
-
-impl IntoIterator for Directory {
- type Item = String;
- type IntoIter = ::std::vec::IntoIter<Self::Item>;
-
- fn into_iter(self) -> Self::IntoIter {
- self.components.into_iter()
- }
-}
-
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct File {
- pub directory: Directory,
- pub file: String,
+ pub file_path: Vec<String>,
}
impl IntoIterator for File {
@@ -36,9 +21,7 @@ impl IntoIterator for File {
type IntoIter = ::std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
- let mut paths = self.directory.components;
- paths.push(self.file);
- paths.into_iter()
+ self.file_path.into_iter()
}
}
@@ -97,13 +80,13 @@ pub trait Canonicalize {
fn canonicalize(&self) -> Self;
}
-impl Canonicalize for Directory {
- fn canonicalize(&self) -> Directory {
- let mut components = Vec::new();
- let mut dir_components = self.clone().into_iter();
+impl Canonicalize for File {
+ fn canonicalize(&self) -> File {
+ let mut file_path = Vec::new();
+ let mut file_path_components = self.clone().into_iter();
loop {
- let component = dir_components.next();
+ let component = file_path_components.next();
match component.as_ref() {
// ───────────────────
// canonicalize(ε) = ε
@@ -114,18 +97,18 @@ impl Canonicalize for Directory {
// canonicalize(directory₀/.) = directory₁
Some(c) if c == "." => continue,
- Some(c) if c == ".." => match dir_components.next() {
+ Some(c) if c == ".." => match file_path_components.next() {
// canonicalize(directory₀) = ε
// ────────────────────────────
// canonicalize(directory₀/..) = /..
- None => components.push("..".to_string()),
+ None => file_path.push("..".to_string()),
// canonicalize(directory₀) = directory₁/..
// ──────────────────────────────────────────────
// canonicalize(directory₀/..) = directory₁/../..
Some(ref c) if c == ".." => {
- components.push("..".to_string());
- components.push("..".to_string());
+ file_path.push("..".to_string());
+ file_path.push("..".to_string());
},
// canonicalize(directory₀) = directory₁/component
@@ -137,17 +120,11 @@ impl Canonicalize for Directory {
// canonicalize(directory₀) = directory₁
// ───────────────────────────────────────────────────────── ; If no other
// canonicalize(directory₀/component) = directory₁/component ; rule matches
- Some(c) => components.push(c.clone()),
+ Some(c) => file_path.push(c.clone()),
}
}
- Directory { components: components }
- }
-}
-
-impl Canonicalize for File {
- fn canonicalize(&self) -> File {
- File { directory: self.directory.canonicalize(), file: self.file.clone() }
+ File { file_path }
}
}