dependency_lister/
lib.rs

1mod file_navigation;
2
3use std::collections::HashSet;
4use std::fmt;
5
6/* ---------------------------- Exported function --------------------------- */
7
8
9/// From a directory, read all d files and read all the dependencies listed in
10/// them.
11pub fn get_all_dependencies_from_dir(dir_path: &str) -> Result<HashSet<String>, DependencyListerError> {
12    file_navigation::get_all_dependencies_from_dir(dir_path)
13}
14
15/* --------------------------------- Errors --------------------------------- */
16
17/// Used to represent errors that can be raised by the dependency listing.
18#[derive(Debug, PartialEq)]
19pub enum DependencyListerError {
20    /// A file name encoding is not supported.
21    UnsuportedFileEncoding(Vec<u8>),
22
23    /// Unable to read a file.
24    UnableToRead(String),
25
26    /// A file is not a link while we expected it to be.
27    NotALink(String),
28
29    /// There is an error manipulating a file name.
30    UnsuportedFileName(String),
31
32    /// We can't read a directory.
33    DirectoryReadingError(String),
34}
35
36use DependencyListerError::*;
37
38impl fmt::Display for DependencyListerError {
39    /// From a `DependencyListerError`, makes an error message that could even be
40    /// shown to the final user.
41    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42        match self {
43            UnsuportedFileEncoding(x) => write!(f, "Unsuported file name encoding. Binary file name: {x:?}"),
44            UnableToRead(x) => write!(f, "Unable to read the file {x}"),
45            NotALink(x) => write!(f, "Expected {x} to be a link but it is not."),
46            UnsuportedFileName(x) => write!(f, "Unsuported file name {x}"),
47            DirectoryReadingError(x) => write!(f, "Error while reading directory {x}"),
48        }
49    }
50}
51