mayuri

Crates.iomayuri
lib.rsmayuri
version0.2.0
created_at2025-07-13 17:54:55.979524+00
updated_at2025-07-13 17:54:55.979524+00
descriptionAn Asynchronous WebSocket Client Library.
homepage
repositoryhttps://github.com/mooncell07/mayuri
max_upload_size
id1750663
size68,719
Nova (mooncell07)

documentation

README

mayuri

A WIP Asynchronous WebSocket Client Library.

Usage

use async_trait::async_trait;
use mayuri::{Context, Transport, WebSocket, WebSocketProtocol};
use tokio;

pub struct App {}

#[async_trait]
impl WebSocketProtocol for App {
    async fn on_connect(&mut self, mut transport: Transport) {
        println!("Connected!");
        transport.write_text(b"hello!").await.unwrap();
    }

    async fn on_message(&mut self, ctx: Context) {
        let msg = ctx.read_text();
        println!("Received: {}", msg);
    }

    async fn on_close(&mut self, _: Context) {
        println!("Closed by the Peer!");
    }
}

#[tokio::main]
async fn main() {
    let mut ws = WebSocket::connect("wss://ws.ifelse.io", App {})
        .await
        .unwrap();
    ws.run().await.unwrap();
}
Commit count: 0

cargo fmt