pub trait Call: Serialize + DeserializeOwned {
type Reply: Serialize + DeserializeOwned;
const PATH: &'static str;
}Expand description
A call: one wire type with its path and the type of its reply (01M3WRD8TBDPA4JNEZY6J4N2EX). The client sends each call with one generic function, and the server makes one route for each.
use riff_core::wire::{Call, Claim};
/// The path of a call and the JSON of its body.
fn request<C: Call>(call: &C) -> (&'static str, String) {
(C::PATH, serde_json::to_string(call).unwrap())
}
let claim = Claim {
me: "riff://mike@pangolin/como-technologies/riff?session=a6cf".parse()?,
thread: "como-technologies/riff".parse()?,
item: "issue-12".into(),
};
let (path, body) = request(&claim);
assert_eq!(path, "/v1/claim");
assert!(body.contains("issue-12"));
let reply: <Claim as Call>::Reply = serde_json::from_str(
r#"{"holder":"riff://mike@pangolin/como-technologies/riff?session=a6cf&claim=issue-12"}"#,
).unwrap();
assert_eq!(reply.holder.claims(), ["issue-12"]);Required Associated Constants§
Required Associated Types§
Sourcetype Reply: Serialize + DeserializeOwned
type Reply: Serialize + DeserializeOwned
The reply to the call.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.