[][src]Function hrx::parse::reduce_raw_entries_and_validate_directory_tree

pub fn reduce_raw_entries_and_validate_directory_tree<Ii: IntoIterator<Item = (HrxPath, HrxEntry)>>(
    iter: Ii
) -> Result<LinkedHashMap<HrxPath, HrxEntry>, HrxError>

Convert a collexion of (path, entry) pairs into a path -> entry map, erroring on any duplicates and file-as-dir usages.

Examples

Dupe:

let mut source_material = vec![("file1.txt".parse().unwrap(),
                                HrxEntry {
                                    comment: None,
                                    data: HrxEntryData::File {
                                        body: Some("First file's contents".to_string())
                                    }
                                }),
                               ("file2.txt".parse().unwrap(),
                                HrxEntry {
                                    comment: None,
                                    data: HrxEntryData::File {
                                        body: Some("Second file's contents".to_string())
                                    }
                                })];

// The no-dupe case
assert_eq!(reduce_raw_entries_and_validate_directory_tree(source_material.clone()),
           Ok(source_material.iter().cloned().collect()));

// Introducing a dupe, now both files have the same paths
source_material[1].0 = source_material[0].0.clone();

assert_eq!(reduce_raw_entries_and_validate_directory_tree(source_material.clone()),
           Err(HrxError::DuplicateEntry(source_material[0].0.to_string())));
// i.e.
assert_eq!(reduce_raw_entries_and_validate_directory_tree(source_material.clone()),
           Err(HrxError::DuplicateEntry("file1.txt".to_string())));

File as directory:

let mut source_material = vec![("file1.txt".parse().unwrap(),
                                HrxEntry {
                                    comment: None,
                                    data: HrxEntryData::File {
                                        body: Some("First file's contents".to_string())
                                    }
                                }),
                               ("file1.txt/subfile.txt".parse().unwrap(),
                                HrxEntry {
                                    comment: None,
                                    data: HrxEntryData::File {
                                        body: Some("Second file's contents, using the first file as directory".to_string())
                                    }
                                })];

assert_eq!(reduce_raw_entries_and_validate_directory_tree(source_material.clone()),
           Err(HrxError::FileAsDirectory(source_material[0].0.to_string(), source_material[1].0.to_string())));
// i.e.
assert_eq!(reduce_raw_entries_and_validate_directory_tree(source_material.clone()),
           Err(HrxError::FileAsDirectory("file1.txt".to_string(), "file1.txt/subfile.txt".to_string())));