Skip to main content

Registry

Struct Registry 

Source
pub struct Registry { /* private fields */ }
Expand description

模型注册表。

Implementations§

Source§

impl Registry

Source

pub fn new() -> Result<Self, Error>

创建默认注册表,包含所有编译进本库的模型族 loader。

§Errors

底层 C ABI 无法创建注册表时返回 Error::NullHandle。

Source

pub fn families(&self) -> Result<Vec<String>, Error>

已注册的模型族列表,例如 ["silero_vad","qwen3_asr"]。

§Errors

C ABI 调用失败或返回的 JSON 无法解析时返回对应 Error 变体。

Source

pub fn loaders(&self) -> Result<Vec<LoaderInfo>, Error>

所有 loader 的声明信息(模型族、任务、端点)。

§Errors

C ABI 调用失败或返回的 JSON 无法解析时返回对应 Error 变体。

Source

pub fn devices() -> Result<Vec<Device>, Error>

枚举所有后端可用的计算设备。

§Errors

C ABI 调用失败或返回的 JSON 无法解析时返回对应 Error 变体。

Source

pub fn supports_family(&self, family: &str) -> bool

判断某个模型族是否已编译进当前引擎。

用于加载前的预检:返回 false 说明该族未启(需对应 model-* feature 或 full-models 重新编译),直接 load 会失败。

注意:false 同时涵盖“内部出错”(此时详情见 C 侧 last_error,但本 签名无法传出);需区分时请用 Registry::try_supports_family。

§Examples
use audio_cpp::Registry;
let registry = Registry::new().unwrap();
// 默认 core 构建恒定包含 silero_vad;随机字符串必然为 false。
assert!(registry.supports_family("silero_vad"));
assert!(!registry.supports_family("definitely_not_a_family"));
Source

pub fn try_supports_family(&self, family: &str) -> Result<bool, Error>

与 Registry::supports_family 同义,但区分“不支持”与“出错”。

C ABI 在传参非法或内部异常时返回 -1(supports_family 把它折成 false);本方法此时返回 Err 并携带 last_error 文本。

§Errors

字符串含 NUL,或 C ABI 内部出错时返回对应 Error 变体。

Source

pub fn inspect(&self, model_path: &str) -> Result<ModelInspection, Error>

预检模型文件:无需真正加载即可获得 metadata / capabilities / 支持的 CLI 选项 / 发现的配置与权重资产。

§Examples
use audio_cpp::Registry;
let registry = Registry::new().unwrap();
let info = registry.inspect("./qwen3-asr-q8_0.gguf").unwrap();
println!("族: {},变体: {}", info.metadata.family, info.metadata.variant);
for opt in &info.cli.request_options {
    println!("  请求选项 {}: {}", opt.name, opt.description);
}
§Errors

C ABI 调用失败、路径非法或返回 JSON 无法解析时返回对应 Error 变体。 若文件不存在或无法被任何 loader 识别,底层会报错(如 Error::NullHandle)。

Source

pub fn load( &self, model_path: &str, family_hint: Option<ModelFamily>, load_options: Option<&str>, ) -> Result<Model, Error>

加载一个模型。

model_path 为权重文件路径(如 .safetensors / .gguf); family_hint 可选,用于指定模型族(GGUF / NeMo safetensors 无法 自动探测族别,须显式指定,见 crate::ModelFamily);load_options 可选,例如 {"weight_id":"..."}。

返回的 Model 共享持有 C 注册表的所有权:本 Registry 释放后 模型仍可继续使用,无需 _registry 三件套持有。

§Errors

路径含 NUL / 非 UTF-8 返回 Error::Nul 或 Error::NonUtf8Path; 底层加载失败返回 Error::NullHandle。

Trait Implementations§

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.