mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
60 lines
1.4 KiB
Rust
60 lines
1.4 KiB
Rust
// Code generated by hostgen. 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, 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>,
|
|
}
|
|
|
|
#[host_fn]
|
|
extern "ExtismHost" {
|
|
fn search_find(input: Json<SearchFindRequest>) -> Json<SearchFindResponse>;
|
|
}
|
|
|
|
/// 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 = unsafe {
|
|
search_find(Json(SearchFindRequest {
|
|
query: query.to_owned(),
|
|
}))?
|
|
};
|
|
|
|
if let Some(err) = response.0.error {
|
|
return Err(Error::msg(err));
|
|
}
|
|
|
|
Ok((response.0.results, response.0.total))
|
|
}
|