#spring-boot #async-trait #path #bean #axum #traits #framework

vine

Vine is rust framework inspired by Spring Boot

12 releases

0.1.4 Oct 28, 2024
0.1.4-dev.10 Sep 10, 2024
0.1.4-dev.6 Aug 12, 2024

#1313 in Web programming

Download history 312/week @ 2024-08-02 184/week @ 2024-08-09 22/week @ 2024-08-16 259/week @ 2024-08-30 127/week @ 2024-09-06 45/week @ 2024-09-13 18/week @ 2024-09-20 15/week @ 2024-09-27 1/week @ 2024-10-04 125/week @ 2024-10-25 14/week @ 2024-11-01

139 downloads per month

Apache-2.0

4KB

Vine

Vine is rust framework inspired by Spring Boot

Example:

use std::sync::Arc;
use async_trait::async_trait;
use axum::extract::Path;
use axum::response::IntoResponse;
use vine::{Bean, controller, get, injectable};
use vine::vine_core::core::Error;

#[async_trait]
trait Service {
    async fn compute(&self, name: String) -> String;
}

#[derive(Bean)]
struct Controller {
    service: Arc<dyn Service + Sync + Send>,
}

#[controller]
impl Controller {
    #[get("/hello/:name")]
    async fn say_hello(&self, Path(name): Path<String>) -> impl IntoResponse {
        self.service.compute(name).await
    }
}

#[derive(Bean)]
struct ServiceImpl {
    #[value("${service.name:DefaultName}")] name: String,
}

#[async_trait]
#[injectable]
impl Service for ServiceImpl {
    async fn compute(&self, name: String) -> String {
        format!("Hello from the {}: {}", &self.name, name)
    }
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    vine::create_app()?
        .exec().await
}

Dependencies

~11–21MB
~296K SLoC