pub fn event_loop<T, E, F>(callback: F) where
    F: Fn(Value) -> Result<T, E>,
    T: Serialize,
    E: Display
Expand description

Starts an ‘event loop’ which listens and writes to stdin and stdout respectively.

Despite its name implying an asynchronous nature, this function blocks waiting for input.

Example

use chrome_native_messaging::event_loop;
use std::io;
use serde::Serialize;
use serde_json::{json, Value};

#[derive(Serialize)]
struct BasicMessage<'a> {
    payload: &'a str
}

event_loop(|value| match value {
    Value::Null => Err("null payload"),
    _ => Ok(BasicMessage { payload: "Hello, World!" })
});