mirror of
https://github.com/navidrome/navidrome.git
synced 2026-12-02 10:06:00 +00:00
58 lines
1.4 KiB
Rust
58 lines
1.4 KiB
Rust
// Code generated by ndpgen. DO NOT EDIT.
|
|
//
|
|
// This file contains client wrappers for the Search host service.
|
|
// It is intended for use in Navidrome plugins built with extism-pdk.
|
|
|
|
use extism_pdk::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct Result {
|
|
pub id: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
struct SearchFindRequest {
|
|
query: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
struct SearchFindResponse {
|
|
#[serde(default)]
|
|
results: Vec<Result>,
|
|
#[serde(default)]
|
|
total: i32,
|
|
#[serde(default)]
|
|
error: Option<String>,
|
|
}
|
|
|
|
#[link(wasm_import_module = "extism:host/user")]
|
|
extern "C" {
|
|
fn search_find(input: u64) -> u64;
|
|
}
|
|
|
|
/// Calls the search_find host function.
|
|
///
|
|
/// # Arguments
|
|
/// * `query` - String parameter.
|
|
///
|
|
/// # Returns
|
|
/// A tuple of (results, total).
|
|
///
|
|
/// # Errors
|
|
/// Returns an error if the host function call fails.
|
|
pub fn find(query: &str) -> Result<(Vec<Result>, i32), Error> {
|
|
let response: SearchFindResponse = unsafe { nd_pdk_types::hostcall::call(search_find, &SearchFindRequest {
|
|
query: query.to_owned(),
|
|
}) }?;
|
|
|
|
if let Some(err) = response.error {
|
|
return Err(Error::msg(err));
|
|
}
|
|
|
|
Ok((response.results, response.total))
|
|
}
|