Skip to main content

surreal_client/
engine.rs

1use async_trait::async_trait;
2use ciborium::Value as CborValue;
3use serde_json::Value;
4
5use super::error::Result;
6
7/// Wire abstraction for SurrealDB RPC. The CBOR method is the real wire path;
8/// the JSON method is a default convenience that transcodes through it.
9#[async_trait]
10pub trait Engine: Send + Sync {
11    async fn send_message_cbor(&mut self, method: &str, params: CborValue) -> Result<CborValue>;
12
13    async fn send_message(&mut self, method: &str, params: Value) -> Result<Value> {
14        let cbor_params = crate::cbor_convert::json_to_cbor(params);
15        let response = self.send_message_cbor(method, cbor_params).await?;
16        Ok(crate::cbor_convert::cbor_to_json(response))
17    }
18}