| Crates.io | sibling |
| lib.rs | sibling |
| version | 2.0.3 |
| created_at | 2026-01-25 22:39:25.712941+00 |
| updated_at | 2026-01-25 22:39:25.712941+00 |
| description | The API for traversing sibling directories (find next/previous directory). |
| homepage | https://tamada.github.io/sibling |
| repository | https://github.com/tamada/sibling |
| max_upload_size | |
| id | 2069739 |
| size | 38,733 |
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.
First, Last, Next, Previous, Random, Keep. (current directory), a directory path, or a file/stdin listlog crate (initialize a logger in your app)To use this crate, add it as a dependency in your Cargo.toml:
[dependencies]
sibling = "2"
use sibling::{Dirs, NexterFactory, NexterType};
fn main() -> sibling::Result<()> {
// Build from the current directory
let dirs = Dirs::new(".")?;
// Move to the next sibling
let next = NexterFactory::build(NexterType::Next)
.next(&dirs)
.map(|d| d.path());
// Move two steps backward
let prev2 = NexterFactory::build(NexterType::Previous)
.next_with(&dirs, 2)
.map(|d| d.path());
println!("next={:?}, prev2={:?}", next, prev2);
Ok(())
}
let dirs = sibling::Dirs::new("/path/to/current")?;
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 = sibling::Dirs::new_from_file("dirlist.txt")?;
// Read from stdin by passing "-"
let dirs = sibling::Dirs::new_from_file("-")?; // stdin
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 directorystep is ignored for all but Next and Previous.
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 errorsSee the workspace LICENSE.