7 releases (breaking)

new 0.7.0 Apr 16, 2024
0.6.0 Apr 9, 2024
0.5.0 Apr 2, 2024
0.4.0 Mar 23, 2024
0.1.0 Mar 5, 2024

#1986 in Procedural macros

Download history 211/week @ 2024-03-01 57/week @ 2024-03-08 175/week @ 2024-03-15 128/week @ 2024-03-22 108/week @ 2024-03-29 129/week @ 2024-04-05

542 downloads per month
Used in predawn

MIT/Apache

71KB
2K SLoC

Predawn

Crates.io version docs.rs docs

predawn is a Rust web framework like Spring Boot.

use predawn::{
    app::{run_app, Hooks},
    controller,
};
use rudi::Singleton;

struct App;

impl Hooks for App {}

#[tokio::main]
async fn main() {
    run_app::<App>().await;
}

#[derive(Clone)]
#[Singleton]
struct Controller;

#[controller]
impl Controller {
    #[handler(paths = ["/"], methods = [post])]
    async fn hello(&self, name: String) -> String {
        format!("Hello {name}")
    }
}

Features

  • Built-in OpenAPI support.
  • Automatic dependency injection.
  • Programmable configuration.

More examples can be found in the examples directories.

More complex example

use std::sync::Arc;

use async_trait::async_trait;
use predawn::{
    app::{run_app, Hooks},
    controller,
};
use rudi::Singleton;

struct App;

impl Hooks for App {}

#[tokio::main]
async fn main() {
    run_app::<App>().await;
}

#[async_trait]
trait Service: Send + Sync {
    fn arc(self) -> Arc<dyn Service>
    where
        Self: Sized + 'static,
    {
        Arc::new(self)
    }

    async fn hello(&self) -> String;
}

#[derive(Clone)]
#[Singleton(binds = [Service::arc])]
struct ServiceImpl;

#[async_trait]
impl Service for ServiceImpl {
    async fn hello(&self) -> String {
        "Hello, World!".to_string()
    }
}

#[derive(Clone)]
#[Singleton]
struct Controller {
    svc: Arc<dyn Service>,
}

#[controller]
impl Controller {
    #[handler(paths = ["/"], methods = [GET])]
    async fn hello(&self) -> String {
        self.svc.hello().await
    }
}

Credits

Dependencies

~1–1.5MB
~30K SLoC