| Crates.io | yrs-tokio-macros |
| lib.rs | yrs-tokio-macros |
| version | 0.1.0 |
| created_at | 2025-05-09 04:45:23.736591+00 |
| updated_at | 2025-05-09 04:45:23.736591+00 |
| description | Axum WebSocket integration for yrs-tokio macros |
| homepage | https://github.com/icode/yrs-tokio |
| repository | https://github.com/icode/yrs-tokio |
| max_upload_size | |
| id | 1666237 |
| size | 84,169 |
macro utils for yrs-tokio
Yrs tokio Into/From generator.
use yrs_tokio_macros::YrsExchange;
#[derive(YrsExchange)]
pub struct YrsSink(SplitSink<WebSocket, AxumMessage>);
Yrs tokio stream generator, use Into<Vec<u8>> convert message.
This macro requires users to add a
futures-core0.3 dependency.
use yrs_tokio_macros::YrsStream;
#[derive(YrsStream)]
pub struct YrsStream(SplitStream<WebSocket>);
Yrs tokio stream generator, use into argument defined convert method, use for not has Into<Vec<u8>> message.
use yrs_tokio_macros::yrs_stream;
#[yrs_stream(into=into_data().into())]
pub struct YrsStream(SplitStream<WebSocket>);
Yrs tokio sink generator.
use yrs_tokio_macros::YrsSink;
#[derive(YrsSink)]
pub struct YrsSink(SplitSink<WebSocket, AxumMessage>);
Yrs tokio common test unit generator.
This macro requires users to add a
tokio-tungstenite0.26 dependency.
use yrs_tokio_macros::yrs_common_test;
#[yrs_common_test]
async fn start_server(
addr: &str,
bcast: Arc<BroadcastGroup>,
) -> Result<JoinHandle<()>, Box<dyn std::error::Error>> {
let addr = SocketAddr::from_str(addr)?;
let bcast_clone = bcast.clone();
Ok(tokio::spawn(async move {
let listener = TcpListener::bind(addr).await.unwrap();
while let Ok((stream, _)) = listener.accept().await {
let bcast = bcast_clone.clone();
tokio::spawn(async move {
let stream = MaybeTlsStream::Plain(stream);
match accept_async(stream).await {
Ok(ws) => handle_connection(ws, bcast).await,
Err(e) => eprintln!("Error during WebSocket handshake: {}", e),
}
});
}
}))
}