ruvchainctl
A library for accessing Admin API of Ruvchain Network router.
It supports both sync and async environment. All you need is to provide
socket that implements either Read and Write traits from std for synchronous
operations or AsyncRead and AsyncWrite traits from an async runtime.
Currently supported runtimes are tokio and futures. If your favorite
runtime is not in the list, consider creating an issue or pull request.
Basic usage
Add either line to your dependencies in Cargo.toml
# Use `std` (synchronous)
= "1"
# Use async runtime
# Available features: "use_tokio" or "use_futures"
= { = "1", = false, = [ "use_tokio" ] }
Next:
use Endpoint;
use UnixStream;
// Create socket using your favorite runtime
let socket = connect/*.await*/.unwrap;
// Attach endpoint to a socket
let mut endpoint = attach;
// First you can get I/O or protocol parsing error
let maybe_error = endpoint.get_self/*.await*/.unwrap;
// Then Admin API can return error (string) to your request
match maybe_error
Advanced usage
You may also want to perform debug_* requests which are deliberately unimplemented in this library.
For this case ruvchainctl allows you to declare a structure of a response you expect to receive.
First, add crates serde and serde_json to your dependecies
# Imports derive macros for `Deserialize` trait
= { = "1", = [ "derive" ] }
# Imports enum `Value` that represents any possible json value
= "1"
Next:
use Endpoint;
use Deserialize;
use Value;
use HashMap;
use Ipv6Addr;
// Connect endpoint
use UnixStream;
let socket = connect/*.await*/.unwrap;
let mut endpoint = attach;
let get_self = endpoint.get_self/*.await*/.unwrap.unwrap;
// Declare a struct you expect to receive
type DebugRemoteGetSelf = ;
// Pass arguments to the request
let mut args = new;
args.insert;
// Perform the request
let maybe_error = endpoint./*.await*/.unwrap;
// Parse the request
match maybe_error