auric_runtime/routing/
route.rs1use crate::Config;
2use anyhow::Result;
3use async_trait::async_trait;
4use serde_json::Value;
5
6#[async_trait]
7pub trait Route {
8 fn init(&mut self, config: &Config) -> Result<()>;
10
11 async fn model(&self, params: &[Value]) -> Result<Value>;
12}
13
14#[cfg(test)]
15mod tests {
16 use super::Route;
17 use crate::Config;
18 use async_trait::async_trait;
19 use serde_json::{Value, json};
20
21 #[test]
22 fn can_implement_route() {
23 #[allow(unused)]
24 struct MyRoute {}
25
26 #[async_trait]
27 impl Route for MyRoute {
28 fn init(&mut self, _config: &Config) -> anyhow::Result<()> {
29 Ok(())
30 }
31 async fn model(&self, _params: &[Value]) -> anyhow::Result<Value> {
32 Ok(json!({
33 "a": "A",
34 "b": "B",
35 }))
36 }
37 }
38 }
39}