zenmanage 1.0.0

Official Zenmanage feature flags SDK for Rust
Documentation
use std::sync::Arc;

use zenmanage::{CacheBackendType, ConfigBuilder, Zenmanage, cache::filesystem::FileSystemCache};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let token = std::env::var("ZENMANAGE_ENVIRONMENT_TOKEN")
        .unwrap_or_else(|_| "srv_your_server_key_here".to_owned());

    let memory_sdk = Zenmanage::new(
        ConfigBuilder::create()
            .with_environment_token(token.clone())
            .with_cache_backend(CacheBackendType::Memory)
            .with_cache_ttl(3600)
            .build()?,
    )?;

    let _ = memory_sdk
        .flags()
        .single("cache-example", Some(false))
        .await?;
    println!("Memory cache configured.");

    let filesystem_cache = Arc::new(FileSystemCache::new("./.zenmanage-cache"));
    let filesystem_sdk = Zenmanage::new(
        ConfigBuilder::create()
            .with_environment_token(token.clone())
            .with_cache(filesystem_cache)
            .build()?,
    )?;

    let _ = filesystem_sdk
        .flags()
        .single("cache-example", Some(false))
        .await?;
    println!("Filesystem cache configured.");

    let null_sdk = Zenmanage::new(
        ConfigBuilder::create()
            .with_environment_token(token)
            .with_cache_backend(CacheBackendType::Null)
            .build()?,
    )?;

    let _ = null_sdk
        .flags()
        .single("cache-example", Some(false))
        .await?;
    println!("Null cache configured.");

    // Sends the last usage reports before the program exits.
    for sdk in [memory_sdk, filesystem_sdk, null_sdk] {
        sdk.flags().flush_usage().await;
    }

    Ok(())
}