commit 541a82a1b76b0a3c34eda1eb4ebfb24c4be328b9
parent 6315ccf0766294ab8a627c84e58cc85929ab39f0
Author: Andy Khramtsov <>
Date: Sat, 7 Feb 2026 16:53:08 +0300
feat: alphabetical sort
Diffstat:
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
@@ -16,6 +16,7 @@ pub mod inventory;
pub mod logging;
pub mod state;
+/// `main`, but returns [`Result`].
pub fn result_main() -> Result<(), Error> {
let args = Args::parse();
let config_path = args.dir.join("config.yaml");
@@ -41,6 +42,7 @@ struct Meta {
blacklist: Option<bool>,
}
+/// Scan workspace
async fn read(state: &State) {
let root = Node::new(
state.config.root.clone(),
@@ -50,6 +52,7 @@ async fn read(state: &State) {
},
);
let mut filetree = Filetree::new(root);
+
let mut buffer = Vec::new();
buffer.extend(
@@ -68,6 +71,7 @@ async fn read(state: &State) {
// This makes it so every prefix goes first.
buffer.sort();
+ // Always partially sorted
let mut buffer = VecDeque::from(buffer);
while let Some(dir) = buffer.pop_front() {
@@ -121,9 +125,17 @@ async fn read(state: &State) {
tracing::debug!("Scanning {:?}", dir.file_name());
let mut iter = tokio::fs::read_dir(&dir).await.unwrap();
+ let mut dir_buffer = Vec::new();
+
while let Some(result) = iter.next_entry().await.unwrap() {
let path = result.path();
- buffer.push_back(path)
+ dir_buffer.push(path)
+ }
+
+ dir_buffer.sort();
+
+ while let Some(path) = dir_buffer.pop() {
+ buffer.push_front(path);
}
}
}
@@ -175,7 +187,7 @@ fn allowed(state: &State, path: &Path) -> bool {
}
fn print(tree: &Filetree<Meta>) -> Result<(), Error> {
- let mut print_buffer = Vec::new();
+ let mut print_buffer = VecDeque::new();
println!(
"{}",
tree.root()
@@ -191,7 +203,7 @@ fn print(tree: &Filetree<Meta>) -> Result<(), Error> {
.children()
.map(|child_id| (1, child_id)),
);
- while let Some((offset, node_id)) = print_buffer.pop() {
+ while let Some((offset, node_id)) = print_buffer.pop_front() {
let node = tree.node(node_id).expect("Shold have the node");
let name = node
.borrow()
@@ -209,11 +221,16 @@ fn print(tree: &Filetree<Meta>) -> Result<(), Error> {
} else {
println!("{}\x1b[2m|\x1b[0m \x1b[31m/{}\x1b[0m", offset_text, name);
}
- print_buffer.extend(
- node.borrow()
- .children()
- .map(|child_id| (offset + 1, child_id)),
- );
+ for child in node
+ .borrow()
+ .children()
+ .map(|child_id| (offset + 1, child_id))
+ .collect::<Vec<_>>()
+ .into_iter()
+ .rev()
+ {
+ print_buffer.push_front(child);
+ }
}
Ok(())
}