atoman

Crates.ioatoman
lib.rsatoman
version0.2.0
created_at2026-01-01 03:59:10.331166+00
updated_at2026-01-16 20:22:30.647304+00
descriptionThis library provides a static data that can be accessed safely and concurrently from any part of your program
homepage
repositoryhttps://github.com/fuderis/rs-atoman
max_upload_size
id2015716
size47,120
Bulat Sh. (fuderis)

documentation

README

githubcrates-iodocs-rs

Atoman (Atomic State)

Atoman is a Rust library for safe concurrent access to static asynchronous data across your application. It provides atomic flags and state wrappers with async setters, getters, and locking mechanisms, bridging synchronous static variables with async runtimes like Tokio.

Features:

  • Global configuration management with file-based persistence (TOML/JSON).

  • Structured logging with async-safe output to files.

  • Feature flags and shared state in async applications.

  • Data is stored in Arc for zero-copy access and thread safety.

Examples:

Atomic Flag:

use atoman::prelude::*;

static IS_ACTIVE: Flag = Flag::new();

#[tokio::main]
async fn main() {
    assert_eq!(IS_ACTIVE.get(), false);
    assert!(IS_ACTIVE.is_false());

    IS_ACTIVE.set(true);
    assert_eq!(IS_ACTIVE.get(), true);

    IS_ACTIVE.swap(false).await;
    assert_eq!(IS_ACTIVE.get(), false);
}

Atomic State:

use atoman::prelude::*;

static CONFIG: State<Config> = State::new();

#[derive(Default, Clone)]
pub struct Config {
    pub count: i32,
}

#[tokio::main]
async fn main() {
    CONFIG.set(Config { count: 10, }).await;
    assert_eq!(CONFIG.get().await.count, 10);

    CONFIG.map(|cfg| cfg.count = 20).await;
    assert_eq!(CONFIG.get().await.count, 20);
    
    CONFIG.lock().await.count = 30;
    assert_eq!(CONFIG.get().await.count, 30);
}

Config:

use atoman::prelude::*;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct Person {
    name: String,
    age: u32
}

impl Default for Person {
    fn default() -> Self {
        Self {
            name: "Bob".to_owned(),
            age: 23
        }
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let mut cfg = Config::<Person>::new(".test/person.toml")?;
    
    assert_eq!(cfg.name, "Bob");
    assert_eq!(cfg.age, 23);

    cfg.age = 24;
    assert_eq!(cfg.age, 24);

    Ok(())
}

Logger:

use atoman::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    Logger::init(".test/logs", 20)?;
        
    info!("Hello, World!");

    Ok(())
}

Feedback:

This library distributed under the MIT license.

You can contact me via GitHub or send a message to my telegram @fuderis. This library is actively evolving, and your suggestions and feedback are always welcome!

Commit count: 15

cargo fmt