Crates.io | predawn-schema-macro |
lib.rs | predawn-schema-macro |
version | |
source | src |
created_at | 2024-10-22 03:11:40.347532 |
updated_at | 2024-10-22 03:11:40.347532 |
description | Macros for predawn-schema |
homepage | https://github.com/ZihanType/predawn |
repository | https://github.com/ZihanType/predawn |
max_upload_size | |
id | 1418197 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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
}
}