wildbird-0.0.5 has been yanked.
Table of contents
Services
Create service instance (Singleton) in one step
use wildbird::derive::*;
#[service(construct = "init")]
struct HelloService {
component_name: String,
}
impl HelloService {
fn init() -> HelloService {
HelloService {
component_name: "Hello penguins 🐧".to_string(),
}
}
fn sey_hello(&self) {
println!("Hello! 👋")
}
}
fn main() {
HelloService.sey_hello();
}
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();
}
use wildbird::derive::*;
#[service]
struct HelloService {
component_name: String,
}
#[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);
}
use wildbird::derive::*;
#[var(name = "HOME")]
fn custom_name() -> String {
std::env::var("HOME").expect("env:HOME not found")
}
fn main() {
println!("Home: {}", HOME);
}
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("⏱️")
}
fn main() {
println!("Users: {}", USERS);
}
Created By
License
MIT
BACK TO TOP ⬆️