Crates.io | predawn-sea-orm |
lib.rs | predawn-sea-orm |
version | 0.9.0 |
source | src |
created_at | 2024-05-03 14:13:08.829692 |
updated_at | 2024-10-11 08:52:39.81009 |
description | Sea Orm Integration for Predawn |
homepage | https://github.com/ZihanType/predawn |
repository | https://github.com/ZihanType/predawn |
max_upload_size | |
id | 1228834 |
size | 27,629 |
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
}
}