#web #extension #io #stdio #json

webext

A library to make native messaging even easier than it already is

1 unstable release

Uses old Rust 2015

0.1.0 Apr 14, 2018

#12 in #stdio

MIT license

4KB


lib.rs:

A library to make native messaging even easier than it already is.

Typically you'd use this in a loop, reading a message in and writing a message out until there are none left to read. Perhaps something like this:

# extern crate webext;
# #[macro_use]
# extern crate serde_derive;
# fn main() {
#
#[derive(Deserialize)]
struct Input { n: usize }

#[derive(Serialize)]
struct Output { n: usize }

// An extension that just adds one to the input number `n`.

while let Some(msg) = webext::read::<Input>() {
    let inp = msg.unwrap();
    let out = Output { n: inp.n + 1 };
    webext::write(&out).unwrap();
}
#
# }

Serde

I strongly recommend that you use this with serde_derive so that you can use your own structs for input and output. Alternatively, you can use the Json type, but that's a lot more annoying to deal with. My favorite enum attributes are #[serde(tag = "type", rename_all = "snake_case")].

Dependencies

~0.5–0.8MB
~17K SLoC

XZ