subspace

Crates.iosubspace
lib.rssubspace
version0.1.0
sourcesrc
created_at2020-06-09 03:41:45.191916
updated_at2020-06-09 03:41:45.191916
descriptionA convenience crate for IPC, using TcpStreams
homepage
repositoryhttps://git.sr.ht/~ron/subspace
max_upload_size
id251744
size26,571
ron (rhvdpols)

documentation

https://git.sr.ht/~ron/subspace

README

subspace

subspace is a highly unstable convenience crate for setting up management of and communication with external processes (nodes).

Example

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
    }
}

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 0

cargo fmt