Crates.io | predawn-macro |
lib.rs | predawn-macro |
version | 0.9.0 |
source | src |
created_at | 2024-03-05 16:33:07.927562 |
updated_at | 2024-10-11 08:51:38.499114 |
description | Macros for predawn |
homepage | https://github.com/ZihanType/predawn |
repository | https://github.com/ZihanType/predawn |
max_upload_size | |
id | 1163214 |
size | 127,742 |
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 {
#[endpoint(paths = ["/"], methods = [post])]
async fn hello(&self, name: String) -> String {
format!("Hello {name}")
}
}
More examples can be found in the examples directories.
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 {
#[endpoint(paths = ["/"], methods = [GET])]
async fn hello(&self) -> String {
self.svc.hello().await
}
}