pub struct TranslationConfig {
pub api_url: String,
pub api_key: Option<String>,
pub timeout: Duration,
pub max_concurrent_requests: usize,
pub enable_cache: bool,
}Expand description
翻译配置
简化的配置结构,包含翻译所需的基本参数。
§示例
use translation_lib::TranslationConfig;
use std::time::Duration;
let config = TranslationConfig {
api_url: "YOUR_API_URL".to_string(),
api_key: Some("YOUR_API_KEY".to_string()),
timeout: Duration::from_secs(30),
max_concurrent_requests: 5,
enable_cache: true,
};Fields§
§api_url: String翻译API地址
api_key: Option<String>API密钥(可选)
timeout: Duration请求超时时间
max_concurrent_requests: usize最大并发请求数
enable_cache: bool是否启用缓存
Implementations§
Source§impl TranslationConfig
impl TranslationConfig
Sourcepub fn with_api_key(self, api_key: String) -> Self
pub fn with_api_key(self, api_key: String) -> Self
设置API密钥
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
设置超时时间
Sourcepub fn with_max_concurrent(self, max_concurrent: usize) -> Self
pub fn with_max_concurrent(self, max_concurrent: usize) -> Self
设置最大并发数
Sourcepub fn with_cache(self, enable_cache: bool) -> Self
pub fn with_cache(self, enable_cache: bool) -> Self
设置是否启用缓存
Sourcepub fn from_env() -> TranslationResult<Self>
pub fn from_env() -> TranslationResult<Self>
从环境变量加载配置
Sourcepub fn validate(&self) -> TranslationResult<()>
pub fn validate(&self) -> TranslationResult<()>
验证配置
Trait Implementations§
Source§impl Clone for TranslationConfig
impl Clone for TranslationConfig
Source§fn clone(&self) -> TranslationConfig
fn clone(&self) -> TranslationConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TranslationConfig
impl Debug for TranslationConfig
Source§impl Default for TranslationConfig
impl Default for TranslationConfig
Source§impl<'de> Deserialize<'de> for TranslationConfig
impl<'de> Deserialize<'de> for TranslationConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TranslationConfig
impl RefUnwindSafe for TranslationConfig
impl Send for TranslationConfig
impl Sync for TranslationConfig
impl Unpin for TranslationConfig
impl UnwindSafe for TranslationConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more