elemental-shared 0.1.0

Lightweight, version-controlled data abstraction for persistent storage.
Documentation
pub mod loader;
pub mod migrator;
pub mod persistor;
pub mod profile;
pub mod scope;
pub mod store;
pub mod version;

#[cfg(test)]
mod shared_test {
    use crate::{migrator::NoMigrator, persistor::json_persistor, profile::Profile, scope::Scope};
    use serde::{Deserialize, Serialize};

    /// A sample configuration struct for testing purposes.
    #[derive(Serialize, Deserialize, Clone)]
    pub struct Config {
        user: String,
    }

    impl Default for Config {
        fn default() -> Self {
            Config {
                user: "Player".to_owned(),
            }
        }
    }

    type ProfileConfig = Profile<Config>;

    #[tokio::test]
    async fn test_profile() {
        let loader = ProfileConfig::load(
            NoMigrator,
            json_persistor("foobar".to_string(), Scope::Dot),
            0,
        )
        .await
        .unwrap();

        println!(
            "{:?}",
            loader.get(|profile| profile.config.user.clone()).await
        ); // Player
        loader
            .set(|profile| profile.config.user = "NewPlayer".to_owned())
            .await
            .unwrap();
        println!(
            "{:?}",
            loader.get(|profile| profile.config.user.clone()).await
        ); // NewPlayer
    }
}