Skip to content

Reloadify is a Rust library enabling hot reloading of configuration files. It supports JSON, TOML, XML, and more, allowing seamless updates to configurations without application restarts. Ideal for Rust projects needing dynamic and responsive configuration management.

License

Notifications You must be signed in to change notification settings

trayvonpan/reloadify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reloadify 🔁

Reloadify is a Rust library designed to facilitate automatic reloading of configuration files in applications. It simplifies the process of detecting changes in configuration files (such as JSON, TOML, XML, etc.) and automatically applying those changes without requiring application restarts.

Features ✨

  • Automatic Reloading: Detects changes in configuration files and automatically reloads them.
  • Supports Multiple Formats: Works with JSON, TOML, XML, and more.
  • Easy Integration: Designed for seamless integration into Rust applications.
  • Live Changes: Returns a configuration receiving channel. When the configuration changes, the caller will receive latest configuration.

Installation 🚀

To use Reloadify in your Rust project, simply add it to your Cargo.toml:

[dependencies]
reloadify = "0.1"

If you want to use the latest version, you can import it like this:

[dependencies]
reloadify = { git = "ssh://[email protected]/trayvonpan/reloadify.git", branch = "main" }

Usage 🛠️

Here's a basic example demonstrating how to use Reloadify to automatically reload a JSON configuration file:

use reloadify::{ConfigId, Format, ReloadableConfig, Reloadify};
use serde::{Deserialize, Serialize};
use std::{path::PathBuf, str::FromStr, time::Duration};

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TsConfig {
    pub extends: String,
    #[serde(rename = "compilerOptions")]
    pub compiler_options: CompilerOptions,
    pub files: Vec<String>,
    pub include: Vec<String>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CompilerOptions {
    #[serde(rename = "outDir")]
    pub out_dir: String,
    pub types: Vec<String>,
}

const TS_CONFIG_ID: &str = "tsconfig";

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let reloadify = Reloadify::new();

    let rx = reloadify.add::<TsConfig>(ReloadableConfig {
        id: ConfigId::new(TS_CONFIG_ID),
        path: PathBuf::from_str("examples/config/tsconfig.spec.json")?,
        format: Format::Json,
        poll_interval: Duration::from_secs(1),
    })?;

    // Optional: Spawn a thread to listen for the latest configuration.
    std::thread::spawn(move || {
        for latest_cfg in rx {
            // Do something with the latest configuration...
            println!("Received latest config: {:?}", latest_cfg);
        }
    });

    let ts_config = reloadify.get::<TsConfig>(ConfigId::new(TS_CONFIG_ID))?;

    // Do something with ts_config...
    println!("{:?}", ts_config);

    Ok(())
}

Documentation 📚

For detailed usage instructions and API reference, see the documentation.

Contributing 🤝

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

License 📝

This project is licensed under the MIT License - see the LICENSE file for details.

About

Reloadify is a Rust library enabling hot reloading of configuration files. It supports JSON, TOML, XML, and more, allowing seamless updates to configurations without application restarts. Ideal for Rust projects needing dynamic and responsive configuration management.

Topics

Resources

License

Stars

Watchers

Forks

Languages