6 releases

0.1.5 May 28, 2022
0.1.4 May 25, 2022

#247 in WebSocket

MIT license

260KB
5.5K SLoC

razer

Control your site with rust

Get Started

Add the script

To add the script all you will have to do is add this to your html

<script src="https://cdn.jsdelivr.net/gh/AMTitan/razer@(your version)/js/razer.min.js"></script>

so an example would be

<script src="https://cdn.jsdelivr.net/gh/AMTitan/razer@0.1.4/js/razer.min.js"></script>

Start your server

To start hosting a server go to this url https://crates.io/crates/razer and on the right it says install copy that line and put it in your Cargo.toml

Getting started

You can read the examples I have made and work off of those and the documentation is here https://docs.rs/razer/


lib.rs:

Razer is serverside way to control your website with rust

Example

use razer::event::event_type::Event::JS;
use razer::event::handler::EventHandler;
use razer::listener::Listener;
use razer::send::send;
use razer::Sender;
use razer::Value;

#[derive(Copy)]
pub struct Handler;

impl Clone for Handler {
    fn clone(&self) -> Self {
        *self
    }
}

impl EventHandler for Handler {
    fn load(&self, _event: Value, ctx: &Sender) {
        send(ctx, JS, "alert(\"Hello\")").unwrap();
    }
}

fn main() {
    Listener::new().start(Handler);
}

this will alert "Hello" when ever someone goes onto your site
To add the script all you will have to do is add this to your html

<script src="https://cdn.jsdelivr.net/gh/AMTitan/razer@(your version)/js/razer.min.js"></script>

an example would be

<script src="https://cdn.jsdelivr.net/gh/AMTitan/razer@0.1.4/js/razer.min.js"></script>

Dependencies

~6.5–9MB
~163K SLoC