The dead easy way to use config files in your rust project

Related tags

Command-line configr
Overview

Configr

The dead easy way to use config files in your project

crates.io

This will load a config.toml file if it exists, otherwise it will create the needed folders and the toml file.
It can either use the OS config directories which are as follows

  • Linux: $XDG_CONFIG_HOME/app-name/config.toml
  • Windows: %APPDATA%/app-name/config.toml
  • Mac OS: $HOME/Library/Application Support/app-name/config.toml

or a custom config directory

Usage

Add the following to your Cargo.toml

configr = "0.7.0"

or use cargo-edit with cargo add configr

then in your project add the following snippet

use configr::{Config, ConfigrDefault};
#[derive(ConfigrDefault, Deserialize, Serialize, Default)]
pub struct BotConfig {
    bot_username: String,
    client_id: String,
    client_secret: String,
    channel: String,
}

replacing BotConfig with your configuration struct

and then load you can load the config, usually at the start of the application with the load function to load from the system config directory

let config = BotConfig::load("bot app", true).unwrap(); // Will load from /home/USER/.config/bot-app/config.toml

or with the load_with_dir function to use a custom config directory

let config = BotConfig::load_with_dir("bot app", "$HOME").unwrap(); // Will load from /home/USER/bot-app/config.toml

Use ConfigrDefault if you want the config.toml to be populated with default values, based on Default implentation, or use Configr if you want it to be populated with empty fields with the correct names

Example of above BotConfig
With Configr

bot_username=
client_id=
client_secret=
channel=

and with ConfigrDefault

bot_username=""
client_id=""
client_secret=""
channel=""

Contributors

I am at the moment not accepting any contributions that don't close an issue.
If you find any problems, or edge cases, please do open an issue!

License

This project is licensed under the unlicense license.

You might also like...
🤖 just is a handy way to save and run project-specific commands.

just just is a handy way to save and run project-specific commands. (非官方中文文档,这里,快看过来!) Commands, called recipes, are stored in a file called justfile

A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!
A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!

uwuifyy A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text! Logo Credits: Jade Nelson Tab

Pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way.

DNG-rs   A pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way. Also containing code for re

🐙 Loads config and hosts for gh CLI in Rust.

gh-config-rs Loads config and hosts for gh CLI in Rust. Getting started [dependencies] gh-config = "0.2" Usage use std::error::Error; use gh_config::*

Voila is a domain-specific language launched through CLI tool for operating with files and directories in massive amounts in a fast & reliable way.

Voila is a domain-specific language designed for doing complex operations to folders & files. It is based on a CLI tool, although you can write your V

Most intuitive global cli maker. *(lazy_static + config-rs + clap)

argone Most intuitive global cli maker. *(lazy_static + config-rs + clap) | Examples | Docs | Latest Note | [dependencies] argone = "0.5" Phases Parsi

A zero-config leptos component to display markdown
A zero-config leptos component to display markdown

A port of yew-markdown using leptos ! Usage You can use this component to render both static and dynamic markdown. Static markdown use leptos::*; {

Opinionated, zero-config linter for JavaScript monorepos
Opinionated, zero-config linter for JavaScript monorepos

Sherif: Opinionated, zero-config linter for JavaScript monorepos About Sherif is an opinionated, zero-config linter for JavaScript monorepos. It runs

An ascii webcam in your console, written as a way of learning rust.

asciicam An ascii webcam in your console, written as a way of learning rust. asciicam picture of me holding a basketball usage only linux is supported

Comments
  • Figure out a good way to do tests

    Figure out a good way to do tests

    Seems like the 3 bests options would be

    • Mocking std::fs::*
    • Mounting FUSE/tmpfs and running tests on a ramdisk
    • Just working on the actual filesystem in a tempdir
    question 
    opened by nyxkrage 2
Owner
Carsten Kragelund Jørgensen
Carsten Kragelund Jørgensen
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.

Connect quickly to your services ?? FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config. Instal

Julien 85 Dec 14, 2022
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.

This repository lists static analysis tools for all programming languages, build tools, config files and more. The official website, analysis-tools.de

Analysis Tools 10.7k Jan 2, 2023
A simple, opinionated way to run containers for tests in your Rust project.

rustainers rustainers is a simple, opinionated way to run containers for tests. TLDR More information about this crate can be found in the crate docum

wefox 4 Nov 23, 2023
SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project.

SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project. With just a few primary configurations, such as project name, you can get started quickly.

Gabriel Michaliszen 4 May 9, 2023
🕺 Run React code snippets/components from your command-line without config

Run React code snippets/components from your command-line without config.

Eliaz Bobadilla 11 Dec 30, 2022
A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

Sergio Benitez 169 Dec 25, 2022
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

refcell.eth 6 Nov 9, 2023
🚀 A fast & easy way to interface w/ Farcaster.xyz via Rust 🦀

farcaster-rs ?? A simple & easy way to interface with Farcaster via Rust ?? Author: Landon Boles GitHub | Farcaster | Bird App Credits MistApproach To

Landon 29 Dec 15, 2022
A dead simple functional testing tool for command line applications

Pharaoh : build that test pyramid! What it is Pharaoh is a dead simple, no permission needed, functional test runner for command line applications, wr

Kevin Sztern 17 Dec 13, 2021
A Turing-complete but dead-simple spaced repetition CLI that helps you learn stuff.

Forne — Learn Stuff Forne is a Turing-complete spaced repetition engine to help you learn stuff your way. What does that mean? Well, there are a few p

Sam Brew 9 May 12, 2023