momentohq / client-sdk-rust

Official Rust SDK for Momento Serverless Cache
Apache License 2.0
12 stars 4 forks source link

look into better differentation between structs with same name #373

Closed cprice404 closed 2 months ago

cprice404 commented 3 months ago

e.g., what does it look like if you try to use the Laptop config for both topics and cache in the same program?

anitarua commented 3 months ago

Using all 3 clients, you'd need to specify the path to each config

use std::time::Duration;

use momento::{
    cache, storage, topics, CacheClient, CredentialProvider, MomentoResult, PreviewStorageClient,
    TopicClient,
};

#[tokio::main(flavor = "current_thread")]
async fn main() -> MomentoResult<()> {

    let storage_client = PreviewStorageClient::builder()
        .configuration(storage::configurations::Laptop::latest())
        .credential_provider(
            CredentialProvider::from_env_var("MOMENTO_API_KEY".to_string())
                .expect("API key should be valid"),
        )
        .build()?;

    let topic_client = TopicClient::builder()
        .configuration(topics::configurations::Laptop::latest())
        .credential_provider(
            CredentialProvider::from_env_var("MOMENTO_API_KEY".to_string())
                .expect("API key should be valid"),
        )
        .build()?;

    let cache_client = CacheClient::builder()
        .default_ttl(Duration::from_secs(60))
        .configuration(cache::configurations::Laptop::latest())
        .credential_provider(
            CredentialProvider::from_env_var("MOMENTO_API_KEY".to_string())
                .expect("API key should be valid"),
        )
        .build()?;

    Ok(())
}
cprice404 commented 3 months ago

Thanks for the example @anitarua ! I honestly think I'm okay with that and can't immediately think of a much better way to do it. @malandis any thoughts?