lst/
lib.rs

1#![warn(
2    rust_2018_compatibility,
3    rust_2018_idioms,
4    rust_2021_compatibility,
5    missing_docs,
6    missing_debug_implementations,
7    missing_copy_implementations
8)]
9
10//! Rust implementation of the POSIX `ls` command
11
12use std::error::Error;
13use std::fmt::{Display, Formatter};
14use std::fs::read_dir;
15use std::path::Path;
16
17/// This is our main entry point
18/// # Examples
19/// ```
20/// # use lst::ls;
21/// ls();
22/// ```
23pub fn ls() {
24    let path = Path::new("./");
25    debug_assert!(path.is_dir());
26
27    let dir_contents = read_dir(path).unwrap();
28    for entry in dir_contents {
29        println!("{}", entry.unwrap().file_name().into_string().unwrap());
30    }
31}
32
33#[derive(Debug)]
34struct LstError;
35
36impl Display for LstError {
37    fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
38        todo!()
39    }
40}
41impl Error for LstError {}
42
43#[cfg(test)]
44mod tests {
45    // use super::*;
46
47    #[test]
48    fn it_works() {
49        let result = 4;
50        assert_eq!(result, 4);
51    }
52}