-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2664a6d
commit d83a510
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Btnify | ||
Hosts a website with buttons for you so you can focus on what matters! | ||
|
||
Btnify is a small libary that lets you host a website with some buttons that will call a function or closure | ||
when clicked. Under the hood, Btnify uses [Axum](https://crates.io/crates/axum). This library is, I must admit, | ||
rather crude, but it works and it's open source! Please leave a pull request with any improvments you have :) | ||
I would appriciate it very much. | ||
|
||
# Examples | ||
|
||
```rust | ||
use btnify::{ | ||
bind_server, | ||
button::{Button, ButtonResponse} | ||
}; | ||
|
||
fn greet_handler(_: &()) -> ButtonResponse { | ||
ButtonResponse::from("Hello world!") | ||
} | ||
|
||
let greet_button = Button::new("Greet", greet_handler); | ||
|
||
let buttons = vec![greet_button]; | ||
|
||
// Notice: bind_server is async and you must await it | ||
bind_server(&"0.0.0.0:3000".parse().unwrap(), buttons, ()) | ||
.await | ||
.unwrap(); | ||
``` | ||
|
||
```rust | ||
use std::sync::Mutex; | ||
use btnify::{ | ||
bind_server, | ||
button::{Button, ButtonResponse} | ||
}; | ||
|
||
struct Counter { | ||
count: Mutex<i32> | ||
} | ||
|
||
fn count_handler(state: &Counter) -> ButtonResponse { | ||
let mut count = state.count.lock().unwrap(); | ||
*count += 1; | ||
format!("The count now is: {count}").into() | ||
} | ||
|
||
let count_button = Button::new("Count", count_handler); | ||
|
||
let buttons = vec![count_button]; | ||
|
||
// Notice: bind_server is async and you must await it | ||
bind_server(&"0.0.0.0:3000".parse().unwrap(), buttons, ()) | ||
.await | ||
.unwrap(); | ||
``` |