Crate webext

Source
Expand description

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:

#[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")].

Functions§

  • Read a message from standard input.
  • Write a message to standard output.

Type Aliases§

  • A type that can encode to and decode from any JSON string.