sausage-plugin part 2: import! with typed clients (sausage_interface::client_rs), TCP endpoints with rpc.endpoint, examples

Part 1 fixes: complete stdout writes, buffered stdin, Rust type names
in schemas, enum variant docs, -32603 for serde errors in handlers,
crate docs and modules. End-to-end check of a generated consumer through
a fake core.
This commit is contained in:
2026-10-23 00:35:45 +01:00
parent ae1cb4cc99
commit 8d3c163992
42 changed files with 3020 additions and 856 deletions
+46
View File
@@ -0,0 +1,46 @@
//! Typed outgoing calls and statically registered imported interfaces.
use crate::{Call, Result};
use serde_json::Value;
use std::{future::IntoFuture, marker::PhantomData};
/// An imported provider document registered by `import!`.
#[doc(hidden)]
pub struct Import {
/// The provider name.
pub name: &'static str,
/// Its complete OpenRPC document.
pub document: &'static str,
}
inventory::collect!(Import);
/// An outgoing call whose result decodes to a generated Rust type.
pub struct TypedCall<T> {
call: Call,
result: PhantomData<T>,
}
impl<T> TypedCall<T> {
/// Wrap an untyped call without sending it yet.
pub fn new(call: Call) -> Self {
Self {
call,
result: PhantomData,
}
}
/// Detach the child process from its caller.
pub fn detach(mut self) -> Self {
self.call = self.call.detach();
self
}
/// Receive progress notifications while the call runs.
pub fn on_notify(mut self, f: impl FnMut(&str, Value) + 'static) -> Self {
self.call = self.call.on_notify(f);
self
}
}
impl<T: serde::de::DeserializeOwned + 'static> IntoFuture for TypedCall<T> {
type Output = Result<T>;
type IntoFuture = futures::future::LocalBoxFuture<'static, Result<T>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { Ok(serde_json::from_value(self.call.await?)?) })
}
}