Skip to main content

ServiceConfig

Struct ServiceConfig 

Source
#[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 不能用字面量构造它 —— 必须走下面这组链式方法。

这不是绕弯路: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");
Source

pub fn new(protocol: Protocol, base_url: &'a str) -> Self

最小构造:只给协议与端点。

Source

pub fn with_preset(self, key: &'a str) -> Self

指定预置 key —— 会校验该预置要求的 extra_fields, 并在 base_url 为空时用预置的地址兜底。

Source

pub fn with_api_key(self, key: &'a str) -> Self

明文密钥。空串 = 不带鉴权(本地服务常见)。

Source

pub fn with_model(self, model: &'a str) -> Self

当前填的模型 id;给了就会校验它在不在端点返回的清单里。

Source

pub fn with_extra(self, extra: &'a [(&'a str, &'a str)]) -> Self

服务商专有字段的实际值。

Trait Implementations§

Source§

impl<'a> Clone for ServiceConfig<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for ServiceConfig<'a>

Source§

impl<'a> Debug for ServiceConfig<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more