Skip to content

PawelJastrzebski/wildbird.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

67 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Rust Framework 🐦 Wildbird


Introduction πŸ‘‹

Welcome to the Wildbird 🐦, designed to streamline your Rust development. Equipped with tools for creating and managing services 🧩 and globals with dependency injection πŸ“Œ functionality.


Table of contents


Services

Create service instance (Singleton) in one step

use wildbird::prelude::*;

// Convert struct to Service + impl construct()

#[service(construct = "init")]
struct HelloService {
    component_name: String,
}

impl HelloService {
    fn init() -> HelloService {
        HelloService {
            component_name: "Hello penguins 🐧".to_string(),
        }
    }

    fn say_hello(&self) {
        println!("Hello! πŸ‘‹")
    }
}

fn main() {
    HelloService.say_hello();
}
  • Async init
use wildbird::derive::*;

#[service(construct = "async init")]
struct AsyncService {}

impl AsyncService {
    async fn init() -> AsyncService {
        AsyncService {}
    }

    fn greeting(&self) {
        println!("Hello πŸ—Ό")
    }
}

fn main() {
    AsyncService.greeting();
}
  • Async init functional
use wildbird::derive::*;

// Convert struct to Service
#[service]
struct HelloService {
    component_name: String,
}

// Impl Service trait construct() 
#[service(construct)]
async fn hello_init() -> HelloService {
    HelloService {
        component_name: "Hello πŸš€".to_string(),
    }
}


Globals

Create global

use wildbird::derive::*;

#[var]
pub fn my_name() -> String {
    String::from("Hawk πŸ¦…")
}

fn main() {
    println!("Hello from πŸ‡΅πŸ‡±, {}", &*MY_NAME);
}
  • Custom name
use wildbird::derive::*;

#[var(name = "HOME")]
fn custom_name() -> String {
    std::env::var("HOME").expect("env:HOME not found")
}

fn main() {
    println!("Home: {}", &*HOME);
}
  • Async init
use std::time::Duration;
use wildbird::derive::*;
use std::thread::sleep;

#[var(name = "USERS")]
async fn http_fetch_users() -> String {
    sleep(Duration::from_millis(200));
    String::from("⏱️")
}
  • callback init
use std::time::Duration;
use wildbird::derive::*;
use std::thread::sleep;

#[var(name = "PORT")]
async fn init_http_service(callback: wildbird::Callback<String>) {
    sleep(Duration::from_millis(200));
    println!("Server started");
    callback.call("8080".to_string());
}


Dependency Injection

Injection support is currently limited to the #[service(construct)] initialization method.

For example:

use wildbird::prelude::*;

#[service]
struct B {
    name: String,
}
#[service(construct)]
async fn b_init() -> B {
    B {
        name: "Baby 🐀".to_string(),
    }
}

#[service]
struct A {
    name: String,
    b_service: Arc<B>
}
#[service(construct)]
async fn a_init(b: Arc<B>) -> A {
    A {
        name: "Automobile πŸš—".to_string(),
        b_service: b
    }
}


Get started

Add dependency

Cargo.toml

[dependencies]
wildbird = "^0.0.11"
Feature flags

Optional features

  • tokio - Use to support tokio async environment
[dependencies]
tokio = "1.28"
wildbird = {version = "^0.0.11", features = ["tokio"]}

Project status

Project is in early state of development. Each release is prior tested but api changes will most likely to happen in the future as the project progress.



Created By


This project is licensed under the MIT License.


BACK TO TOP ⬆️



Releases

No releases published

Packages

No packages published