Skip to main content

auric_runtime/routing/
route.rs

1use super::RouteModel;
2use crate::Context;
3use anyhow::Result;
4use async_trait::async_trait;
5
6#[async_trait]
7pub trait Route {
8    // Initialize the route
9    fn init(&mut self, context: &dyn Context) -> Result<()>;
10
11    async fn model(&self, params: &[serde_json::Value]) -> Result<RouteModel>;
12}
13
14#[cfg(test)]
15mod tests {
16    use super::{Route, RouteModel};
17    use crate::Context;
18    use async_trait::async_trait;
19    use serde_json::{Value, json};
20
21    #[test]
22    fn can_implement_route() {
23        struct MyRoute {}
24
25        #[async_trait]
26        impl Route for MyRoute {
27            fn init(&mut self, _context: &dyn Context) -> anyhow::Result<()> {
28                Ok(())
29            }
30            async fn model(&self, _params: &[Value]) -> anyhow::Result<RouteModel> {
31                Ok(RouteModel::Json(json!({
32                    "a": "A",
33                    "b": "B",
34                })))
35            }
36        }
37
38        let _ = MyRoute {};
39    }
40}