1 unstable release
Uses new Rust 2024
| 0.1.5 | May 11, 2026 |
|---|
#1742 in Filesystem
5KB
CTErrors: A Rust Error Handling Module
A lightweight, descriptive error enumeration for Rust projects, designed to handle common file system operations, data validation, and custom error messaging.
Features
- File System Errors: Comprehensive coverage for reading, writing, creating, and deleting files.
- Data Validation: Built-in variants for index bounds, length limits, and type/value integrity.
- Custom Errors: Flexible
CustomError(String)variant for domain-specific error messages. - Ease of Use: Implements
Debug,Clone,PartialEq, andDisplay.
Installation
Add this module to your project by including the source in your src/ directory (e.g., src/errors.rs).
API Reference
| Variant | Description |
|---|---|
| FileWriteError | Error occurred while writing to a file. |
| FileCreateError | Error occurred while creating a file. |
| FileDeleteError | Error occurred while deleting a file. |
| FileReadError | Error occurred while reading a file. |
| ByteReadError | Error occurred while reading a byte. |
| ByteWriteError | Error occurred while writing a byte. |
| ContentsEmpty | Contents of the file are empty. |
| IndexError | Index out of bounds. |
| MaxLengthExceeded | Maximum length exceeded. |
| TypeError, | Key error. |
| ValueError | Value error. |
| NotFound | Resource or item not found. |
| CustomError(String) | A dynamic error message. |
Usage
Basic Example
use crate::errors::CTErrors;
fn read_config(path: &str) -> Result<String, CTErrors> {
if path.is_empty() {
return Err(CTErrors::FileReadError);
}
// Simulate finding nothing
Err(CTErrors::NotFound)
}
fn main() {
match read_config("") {
Err(e) => println!("Error encountered: {}" , e),
_ => println!("Success!"),
}
}