remote_trait_object/
service.rs1pub mod export_import;
2pub mod handle;
3pub mod id;
4mod null;
5pub mod serde_support;
6
7use crate::forwarder::ServiceObjectId;
8use crate::port::Port;
9use std::sync::Weak;
10
11pub use handle::Handle;
12pub use null::{create_null_service, NullService};
13pub type MethodId = u32;
14
15pub trait Dispatch: Send + Sync {
18 fn dispatch_and_call(&self, method: MethodId, args: &[u8]) -> Vec<u8>;
19}
20
21impl<F> Dispatch for F
22where
23 F: Fn(MethodId, &[u8]) -> Vec<u8> + Send + Sync,
24{
25 fn dispatch_and_call(&self, method: MethodId, args: &[u8]) -> Vec<u8> {
26 self(method, args)
27 }
28}
29
30pub trait Service: Send + Sync {}
57
58pub trait SerdeFormat {
60 #[allow(clippy::result_unit_err)]
61 fn to_vec<S: serde::Serialize>(s: &S) -> Result<Vec<u8>, ()>;
62 #[allow(clippy::result_unit_err)]
63 fn from_slice<D: serde::de::DeserializeOwned>(data: &[u8]) -> Result<D, ()>;
64}
65
66pub struct Cbor;
69
70impl SerdeFormat for Cbor {
71 fn to_vec<S: serde::Serialize>(s: &S) -> Result<Vec<u8>, ()> {
72 serde_cbor::to_vec(s).map_err(|_| ())
73 }
74
75 fn from_slice<D: serde::de::DeserializeOwned>(data: &[u8]) -> Result<D, ()> {
76 serde_cbor::from_slice(data).map_err(|_| ())
77 }
78}