Skip to main content

zotron_cli/
rpc.rs

1//! RPC abstraction: the `RpcCaller` trait, the live `ZoteroRpc` implementation,
2//! and small client-call helpers.
3
4use serde_json::Value;
5use zotron_rpc::ZoteroRpc;
6
7pub trait RpcCaller {
8    fn call(&mut self, method: &str, params: Option<Value>) -> Result<Value, String>;
9}
10
11impl RpcCaller for ZoteroRpc {
12    fn call(&mut self, method: &str, params: Option<Value>) -> Result<Value, String> {
13        self.call(method, params).map_err(|err| err.to_string())
14    }
15}
16
17pub(crate) fn call_json(
18    client: &mut impl RpcCaller,
19    method: &str,
20    params: Option<Value>,
21) -> Result<Value, String> {
22    client.call(method, params)
23}