Trait KeyFromEnv

Source
pub trait KeyFromEnv {
    const KEY_NAME: &'static str;

    // Provided methods
    fn find_key() -> Option<String> { ... }
    fn find_key_with_user() -> String { ... }
    fn prompt_save_to_env() -> bool { ... }
    fn read_single_key() -> Result<String, Box<dyn Error>> { ... }
    fn save_to_env_file(api_key: &str) -> Result<(), Box<dyn Error>> { ... }
}
Expand description

Trait for types that can retrieve their configuration key from environment variables

Required Associated Constants§

Source

const KEY_NAME: &'static str

The environment variable name for this client’s API key

Provided Methods§

Source

fn find_key() -> Option<String>

Find the API key by checking environment variables first, then .env file

Source

fn find_key_with_user() -> String

Find the API key with user fallback - waits 15 seconds for user input then panics

Source

fn prompt_save_to_env() -> bool

Prompt user if they want to save the API key to .env file Uses single keystroke detection with fallback to Enter

Source

fn read_single_key() -> Result<String, Box<dyn Error>>

Attempt to read a single keystroke

Source

fn save_to_env_file(api_key: &str) -> Result<(), Box<dyn Error>>

Save the API key to .env file

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl KeyFromEnv for ClaudeConfig

Source§

const KEY_NAME: &'static str = "ANTHROPIC_API_KEY"

Source§

impl KeyFromEnv for AnthropicProvider

Source§

const KEY_NAME: &'static str = "ANTHROPIC_API_KEY"

Source§

impl KeyFromEnv for DeepSeekConfig

Source§

const KEY_NAME: &'static str = "DEEPSEEK_API_KEY"