| Crates.io | configme |
| lib.rs | configme |
| version | 1.0.1 |
| created_at | 2025-10-20 01:26:45.319836+00 |
| updated_at | 2025-10-20 01:26:45.319836+00 |
| description | Ensure your app’s config directory and SQLite setup are always ready to go. |
| homepage | |
| repository | https://github.com/canmi21/configme |
| max_upload_size | |
| id | 1891263 |
| size | 73,505 |
configme is a Rust library that simplifies setting up your application's configuration directory and SQLite databases. It ensures directories and files are created if they don't exist, handling paths with tilde expansion for user home directories. It's designed for asynchronous applications and supports optional features for fancy logging and SQLite integration.
/opt.~/.appname).Add this to your Cargo.toml:
[dependencies]
configme = "1"
For optional features:
configme = { version = "1", features = ["fancy"] }configme = { version = "1", features = ["sqlite"] }configme = { version = "1", features = ["fancy", "sqlite"] }The library provides macros for easy setup. All operations are designed to be idempotent—running them multiple times won't recreate existing files or directories.
Use the init_config! macro to initialize the config directory. It sets a global path that other macros use.
use configme::*;
#[tokio::main]
async fn main() {
// Initializes ~/.configme (using crate name by default)
init_config!();
// Create subdirectories
create_subdirs!("cache", "logs");
// Create an empty file
create_file!("settings.json");
// Get the config directory path
let dir = get_config_dir();
println!("Config directory: {}", dir.display());
}
You can customize the directory name, location, and visibility:
name: Custom app name (defaults to crate name via env!("CARGO_PKG_NAME")).where: "home" (default, e.g., ~/appname) or "opt" (e.g., /opt/appname).hide: true to add a leading dot (e.g., ~/.appname).use configme::*;
#[tokio::main]
async fn main() {
// Initializes ~/.example in home directory, hidden
init_config!(name = "example", where = "home", hide = true);
let dir = get_config_dir();
println!("Config directory: {}", dir.display());
}
Create an empty SQLite database file asynchronously. It ensures the parent directory exists.
use configme::*;
#[tokio::main]
async fn main() {
init_config!();
create_subdirs!("db");
// Creates db/app.sqlite if it doesn't exist
sqlite!("db/app.sqlite").await;
let dir = get_config_dir();
println!("Config directory: {}", dir.display());
}
When enabled, logs use colorful output via the fancy-log crate. Without it, logs fall back to plain println! or eprintln!.
The crate includes example files in the examples/ directory:
demo.rs: Basic directory and file creation.demo_sqlite.rs: SQLite database creation (requires "sqlite" feature).demo_fancy.rs: Custom hidden directory with fancy logging (requires "fancy" feature).Run them with Cargo:
cargo run --example demo
cargo run --example demo_sqlite --features sqlite
cargo run --example demo_fancy --features fancy
tokio (for async runtime), shellexpand (for path expansion).fancy-log (for "fancy" feature), sqlx (for "sqlite" feature).This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or pull request on GitHub.
tokio, sqlx, and shellexpand.