summaryrefslogtreecommitdiff
path: root/src/data.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/data.rs')
-rw-r--r--src/data.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/data.rs b/src/data.rs
index f652a13..6976352 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -14,3 +14,29 @@ pub fn get_data1() -> SimpleFsData {
1, vec!(("hello".to_string(),
SimpleFsData::File(2, "Hello, World!".to_string()))))
}
+
+pub fn traverse_fs<F>(file: SimpleFsData, f: &mut F)
+ where F: FnMut(& SimpleFsData) {
+ f(&file);
+ match file {
+ SimpleFsData::Directory(_, children) => for (_, file) in children {
+ traverse_fs(file, f);
+ },
+ _ => (),
+ }
+}
+
+#[test]
+fn traverse() {
+ let mut result = String::new();
+ {
+ let mut f = |ref file: &SimpleFsData| {
+ match *file {
+ &SimpleFsData::File(_, ref s) => result += &s,
+ _ => (),
+ };
+ };
+ traverse_fs(get_data1(), &mut f);
+ }
+ assert_eq!("Hello, World!", result);
+}