use crate::Router;
use async_trait::async_trait;
use std::sync::Arc;
#[async_trait]
#[allow(unused)]
pub trait Route<M> {
async fn model(&self, params: serde_json::Value) -> anyhow::Result<M>;
fn name(&self) -> &'static str;
fn router(&self) -> Arc<Router>;
}
#[cfg(test)]
mod tests {
use super::Route;
use crate::Router;
use async_trait::async_trait;
use std::sync::Arc;
#[test]
fn can_implement_route() {
struct MyModel {
#[allow(unused)]
pub a: String,
#[allow(unused)]
pub b: String,
}
struct MyRoute {
router: Arc<Router>,
}
#[async_trait]
impl Route<MyModel> for MyRoute {
async fn model(&self, _params: serde_json::Value) -> anyhow::Result<MyModel> {
Ok(MyModel {
a: "A".to_string(),
b: "B".to_string(),
})
}
fn name(&self) -> &'static str {
"my-route"
}
fn router(&self) -> Arc<Router> {
self.router.clone()
}
}
}
}