gemini_crate 0.1.0

A robust Rust client library for Google's Gemini AI API with built-in error handling, retry logic, and comprehensive model support
Documentation
//! This module handles the configuration for the Gemini client.
use crate::errors::Error;
use dotenvy::dotenv;
use std::env;

/// Represents the application's configuration.
///
/// This struct holds the API key required for authenticating with the Gemini API.
#[derive(Clone)]
pub struct Config {
    api_key: String,
}

impl Config {
    /// Creates a new `Config` instance by loading settings from the environment.
    ///
    /// It first attempts to load variables from a `.env` file in the current directory.
    /// Then, it reads the `GEMINI_API_KEY` environment variable.
    ///
    /// # Errors
    ///
    /// This function will return an error if the `GEMINI_API_KEY` environment variable is not set.
    pub fn new() -> Result<Self, Error> {
        dotenv().ok(); // Load .env file if it exists

        let api_key = env::var("GEMINI_API_KEY")
            .map_err(|_| Error::Config("GEMINI_API_KEY must be set".to_string()))?;

        Ok(Self { api_key })
    }

    /// Returns the Gemini API key.
    pub fn api_key(&self) -> &str {
        &self.api_key
    }

    /// Creates a new `Config` instance from a given API key for testing.
    #[cfg(test)]
    pub fn from_api_key(api_key: String) -> Self {
        Self { api_key }
    }
}