auric-runtime 0.1.4

Runtime for the Ember-inspired Auric SPA framework
Documentation
use crate::Config;
use anyhow::Result;
use async_trait::async_trait;
use serde_json::Value;

#[async_trait]
pub trait Route {
    // Initialize the route
    fn init(&mut self, config: &Config) -> Result<()>;

    async fn model(&self, params: &[Value]) -> Result<Value>;
}

#[cfg(test)]
mod tests {
    use super::Route;
    use crate::Config;
    use async_trait::async_trait;
    use serde_json::{Value, json};

    #[test]
    fn can_implement_route() {
        #[allow(unused)]
        struct MyRoute {}

        #[async_trait]
        impl Route for MyRoute {
            fn init(&mut self, _config: &Config) -> anyhow::Result<()> {
                Ok(())
            }
            async fn model(&self, _params: &[Value]) -> anyhow::Result<Value> {
                Ok(json!({
                    "a": "A",
                    "b": "B",
                }))
            }
        }
    }
}