#[non_exhaustive]pub struct ServiceConfig<'a> {
pub preset_key: Option<&'a str>,
pub protocol: Protocol,
pub base_url: &'a str,
pub api_key: &'a str,
pub model: &'a str,
pub extra: &'a [(&'a str, &'a str)],
}Expand description
发起验证所需的配置 —— 全部来自调用方表单里正在编辑的值。
刻意用借用而非 String:调用方通常直接从表单字段取,不该为验证一次而 clone。
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.preset_key: Option<&'a str>预置 key。给了就会校验该预置要求的 extra_fields,并在 base_url 为空时用它兜底
protocol: Protocol协议:决定鉴权头的形式
base_url: &'a str端点地址;空串 = 用预置的 base_url
api_key: &'a str明文密钥;空串 = 不带鉴权(本地服务常见)
model: &'a str当前填的模型 id;空串 = 不校验模型是否存在
extra: &'a [(&'a str, &'a str)]专有字段的实际值,(key, value) 对
Implementations§
Source§impl<'a> ServiceConfig<'a>
🔴 本类型带 #[non_exhaustive],外部 crate 不能用字面量构造它 ——
必须走下面这组链式方法。
impl<'a> ServiceConfig<'a>
🔴 本类型带 #[non_exhaustive],外部 crate 不能用字面量构造它 ——
必须走下面这组链式方法。
这不是绕弯路:non_exhaustive 让本 crate 以后加字段只算 minor 版本,
代价就是调用方不能写 ServiceConfig { .. }。入参类型上用它,
必须同时提供完整的 builder,否则下游根本没法用(实测踩过 E0639)。
let cfg = ServiceConfig::new(Protocol::OpenAiCompatible, "https://api.deepseek.com/v1")
.with_preset("deepseek")
.with_api_key("sk-…")
.with_model("deepseek-flash");Sourcepub fn with_preset(self, key: &'a str) -> Self
pub fn with_preset(self, key: &'a str) -> Self
指定预置 key —— 会校验该预置要求的 extra_fields,
并在 base_url 为空时用预置的地址兜底。
Sourcepub fn with_api_key(self, key: &'a str) -> Self
pub fn with_api_key(self, key: &'a str) -> Self
明文密钥。空串 = 不带鉴权(本地服务常见)。
Sourcepub fn with_model(self, model: &'a str) -> Self
pub fn with_model(self, model: &'a str) -> Self
当前填的模型 id;给了就会校验它在不在端点返回的清单里。
Sourcepub fn with_extra(self, extra: &'a [(&'a str, &'a str)]) -> Self
pub fn with_extra(self, extra: &'a [(&'a str, &'a str)]) -> Self
服务商专有字段的实际值。
Trait Implementations§
Source§impl<'a> Clone for ServiceConfig<'a>
impl<'a> Clone for ServiceConfig<'a>
impl<'a> Copy for ServiceConfig<'a>
Auto Trait Implementations§
impl<'a> Freeze for ServiceConfig<'a>
impl<'a> RefUnwindSafe for ServiceConfig<'a>
impl<'a> Send for ServiceConfig<'a>
impl<'a> Sync for ServiceConfig<'a>
impl<'a> Unpin for ServiceConfig<'a>
impl<'a> UnsafeUnpin for ServiceConfig<'a>
impl<'a> UnwindSafe for ServiceConfig<'a>
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