sibling (library)
A small Rust library for traversing sibling directories (directories that share the same parent) in alphabetical order.
From a current directory, you can get the “next” directory using several strategies: first, last, next, previous, random, and keep.
The CLI in cli/ consumes this library.
Features
- Simple API to enumerate and navigate sibling directories
- Switchable strategies:
First,Last,Next,Previous,Random,Keep - Initialize from
.(current directory), a directory path, or a file/stdin list - Lightweight logging via the
logcrate (initialize a logger in your app)
How to use
To use this crate, add it as a dependency in your Cargo.toml:
[]
= "2"
Quick Start
use ;
Inputs
1) From a directory path
let dirs = new?;
2) From a file (or stdin)
Dirs::new_from_file() builds Dirs from a list of directories (one per line).
Optionally, the first line may set the parent as parent:/path/to/parent.
Example: dirlist.txt
parent:/projects
a
b
c
let dirs = new_from_file?;
// Read from stdin by passing "-"
let dirs = new_from_file?; // stdin
Strategies (NexterType)
First: the first sibling directoryLast: the last sibling directoryNext: move forward by the given step (default: 1)Previous: move backward by the given step (default: 1)Random: pick one at randomKeep: keep the current directory
step is ignored for all but Next and Previous.
Errors
The library exposes type Result<T> = std::result::Result<T, Error>.
Main error variants include:
Error::Io(std::io::Error): file system I/O errorError::NotFound(PathBuf): path does not existError::NotDir(PathBuf): not a directoryError::NotFile(PathBuf): not a fileError::NoParent(PathBuf): no parent directoryError::Fatal(String): fatal error with messageError::Array(Vec<Error>): aggregation of multiple errors
License
See the workspace LICENSE.