Skip to main content

typesafe_rs/
backend.rs

1use std::future::Future;
2
3use crate::Client;
4use crate::config::CallOptions;
5use crate::error::Error;
6use crate::types::{SystemOneRequest, SystemOneResponse};
7
8/// Pluggable System One evaluator.
9///
10/// [`Client`](crate::Client) implements this so callers can depend on the trait
11/// rather than the HTTP type. Additional backends (LLM, Cascade) are planned.
12pub trait Backend: Send + Sync {
13    /// Stable backend name, e.g. `"typesafe"`.
14    fn name(&self) -> &str;
15
16    /// Evaluate `req` with per-call options.
17    fn system_one(
18        &self,
19        req: &SystemOneRequest,
20        opts: &CallOptions,
21    ) -> impl Future<Output = Result<SystemOneResponse, Error>> + Send;
22}
23
24impl Backend for Client {
25    fn name(&self) -> &str {
26        "typesafe"
27    }
28
29    fn system_one(
30        &self,
31        req: &SystemOneRequest,
32        opts: &CallOptions,
33    ) -> impl Future<Output = Result<SystemOneResponse, Error>> + Send {
34        let this = self.clone();
35        let req = req.clone();
36        let opts = opts.clone();
37        async move { this.system_one_with(&req, opts).await }
38    }
39}