Crates.io | subspace |
lib.rs | subspace |
version | 0.1.0 |
source | src |
created_at | 2020-06-09 03:41:45.191916 |
updated_at | 2020-06-09 03:41:45.191916 |
description | A convenience crate for IPC, using TcpStreams |
homepage | |
repository | https://git.sr.ht/~ron/subspace |
max_upload_size | |
id | 251744 |
size | 26,571 |
subspace is a highly unstable convenience crate for setting up management of and communication with external processes (nodes).
Add subspace
to your Cargo.toml
[dependencies]
subspace = "0.1.0"
In your main process, create an External
struct.
// For the full example, check tests/node_tests.rs
// name is the path + filename of the executable to launch
let name = "target/debug/example";
// address is the hostname + port the node should bind to
let address = "localhost:2345";
External::new(&name, address.to_string())?;
In your secondary process, parse command line arguments (done with clap in the example) and create a node.
fn main() {
// Commandline arguments handled with clap, External will call the executable with --addr localhost:2345
//
let matches = App::new("Subspace example node")
.author("ron")
.about("An example process for subspace integration tests")
.version("0.1")
.arg(
Arg::with_name("addr")
.short("a")
.long("addr")
.help("Address this node should bind to")
.takes_value(true),
)
.get_matches();
// get address to bind to from arguments, then construct "this node"
//
let addr = matches.value_of("addr").unwrap();
let mut node = Node::new(addr).unwrap();
// call node.get_node_message() in this executables message loop, and act on it
//
loop {
match node.get_node_message() {
Some(NodeMessage::Exit) => break,
_ => (),
}
// do work
}
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.