Rust high-level wrapper around NNG (Nanomsg-Next-Gen)
Features:
- Use nngaio for asynchronous I/O
- Use nngctx for advanced protocol handling
- Leverage futures crate for ease of use with tokio and eventual support of async
/await
Simple:
rust
use runng::*;
fn test() -> Result<(), NngFail> {
const url: &str = "inproc://test";
let factory = Latest::new();
let rep = factory.replier_open()?.listen(&url)?;
let req = factory.requester_open()?.dial(&url)?;
req.send(msg::NngMsg::new()?)?;
rep.recv()?;
Ok(())
}
Asynchronous I/O: ```rust extern crate futures; extern crate runng; use futures::{ future::Future, stream::Stream, }; use runng::{ *, protocol::{ AsyncReply, AsyncRequest, AsyncSocket, }, };
fn aio() -> NngReturn { const url: &str = "inproc://test";
let factory = Latest::new();
let mut rep_ctx = factory
.replier_open()?
.listen(&url)?
.create_async_context()?;
let requester = factory.requester_open()?.dial(&url)?;
let mut req_ctx = requester.create_async_context()?;
let req_future = req_ctx.send(msg::NngMsg::new()?);
rep_ctx.receive()
.take(1).for_each(|_request|{
let msg = msg::NngMsg::new().unwrap();
rep_ctx.reply(msg).wait().unwrap();
Ok(())
}).wait();
req_future.wait().unwrap()?;
Ok(())
} ```
Additional examples in examples/
folder.