pinakes-plugin-api: update manifest, types, and wasm interface
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic574cc8d1d24967a8c997a3092037e526a6a6964
This commit is contained in:
parent
eb6c0a3577
commit
c8425a4c34
4 changed files with 53 additions and 17 deletions
|
|
@ -47,8 +47,8 @@ pub enum WasmResult<T> {
|
|||
impl<T> From<Result<T, String>> for WasmResult<T> {
|
||||
fn from(r: Result<T, String>) -> Self {
|
||||
match r {
|
||||
Ok(v) => WasmResult::Ok(v),
|
||||
Err(e) => WasmResult::Err(e),
|
||||
Ok(v) => Self::Ok(v),
|
||||
Err(e) => Self::Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -112,22 +112,35 @@ pub struct HttpResponse {
|
|||
|
||||
/// Helper functions for serializing/deserializing data across WASM boundary
|
||||
pub mod helpers {
|
||||
use super::*;
|
||||
use super::{Deserialize, PluginResponse, Serialize, WasmResult};
|
||||
|
||||
/// Serialize a value to bytes for passing to WASM
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error string if the value cannot be serialized to JSON.
|
||||
pub fn serialize<T: Serialize>(value: &T) -> Result<Vec<u8>, String> {
|
||||
serde_json::to_vec(value).map_err(|e| format!("Serialization error: {}", e))
|
||||
serde_json::to_vec(value).map_err(|e| format!("Serialization error: {e}"))
|
||||
}
|
||||
|
||||
/// Deserialize bytes from WASM to a value
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error string if the bytes cannot be deserialized as `T`.
|
||||
pub fn deserialize<T: for<'de> Deserialize<'de>>(
|
||||
bytes: &[u8],
|
||||
) -> Result<T, String> {
|
||||
serde_json::from_slice(bytes)
|
||||
.map_err(|e| format!("Deserialization error: {}", e))
|
||||
.map_err(|e| format!("Deserialization error: {e}"))
|
||||
}
|
||||
|
||||
/// Create a success response
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error string if `value` or the response envelope cannot be
|
||||
/// serialized.
|
||||
pub fn ok_response<T: Serialize>(
|
||||
request_id: String,
|
||||
value: &T,
|
||||
|
|
@ -138,6 +151,10 @@ pub mod helpers {
|
|||
}
|
||||
|
||||
/// Create an error response
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error string if the response envelope cannot be serialized.
|
||||
pub fn error_response(
|
||||
request_id: String,
|
||||
error: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue