async fn oneshot<Request>(&self, request: Request) -> Result<Request::Response, failure::Error>
    where
        Request: shellrt_api::v0::ReqMarker,
    {
        let mut child = Command::new(&self.bin)
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()?;

        let mut child_stdin = child.stdin().take().unwrap();
        let mut child_stdout = child.stdout().take().unwrap();

        let input = Input::new(request);
        let req = serde_json::to_vec(&input)?;

        info!("input payload: {:#?}", input);
        debug!("---> {}", String::from_utf8_lossy(&req));

        child_stdin.write(&req).await?;
        std::mem::drop(child_stdin);

        let _status = child.await?;

        let mut res = Vec::new();
        child_stdout.read_to_end(&mut res).await?;
        debug!("<--- {}", String::from_utf8_lossy(&res));

        let output: Output<Request::Response> = serde_json::from_slice(&res)?;

        info!("output payload: {:#?}", output);

        // TODO: use semver for more lenient version compatibility
        if output.version() != VERSION {
            failure::bail!("Bad response: invalid API version");
        }

        output
            .into_inner()
            .map_err(|e| failure::err_msg(format!("API error: {:#?}", e)))
    }
/// Send a Request to the plugin, blocking until the plugin returns some
/// Output. Fails if output is malformed, there is a version mismatch, or
/// the operation failed with an error.
Send a Request to the plugin, blocking until the plugin returns some
Output. Fails if output is malformed, there is a version mismatch, or
the operation failed with an error.
Send a Request to the plugin blocking until the plugin returns some Output . Fails if output is malformed there is a version mismatch or the operation failed with an error .
async fn oneshot<Request>(&self, request: Request) -> Result<Request::Response, failure::Error>
    where
        Request: shellrt_api::v0::ReqMarker,
    {
        let mut child = Command::new(&self.bin)
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()?;
        let mut child_stdin = child.stdin().take().unwrap();
        let mut child_stdout = child.stdout().take().unwrap();
        let input = Input::new(request);
        let req = serde_json::to_vec(&input)?;
        info!("input payload: {:#?}", input);
        debug!("---> {}", String::from_utf8_lossy(&req));
        child_stdin.write(&req).await?;
        std::mem::drop(child_stdin);
        let _status = child.await?;
        let mut res = Vec::new();
        child_stdout.read_to_end(&mut res).await?;
        debug!("<--- {}", String::from_utf8_lossy(&res));
        let output: Output<Request::Response> = serde_json::from_slice(&res)?;
        info!("output payload: {:#?}", output);
        // TODO: use semver for more lenient version compatibility
        if output.version() != VERSION {
            failure::bail!("Bad response: invalid API version");
        }
        output
            .into_inner()
            .map_err(|e| failure::err_msg(format!("API error: {:#?}", e)))
    }
async fn oneshot < Request > ( & self , request : Request ) -> Result < Request :: Response , failure :: Error > where Request : shellrt_api :: v0 :: ReqMarker , { let mut child = Command :: new ( & self . bin ) . stdin ( Stdio :: piped ( ) ) . stdout ( Stdio :: piped ( ) ) . spawn ( ) ? ; let mut child_stdin = child . stdin ( ) . take ( ) . unwrap ( ) ; let mut child_stdout = child . stdout ( ) . take ( ) . unwrap ( ) ; let input = Input :: new ( request ) ; let req = serde_json :: to_vec ( & input ) ? ; info ! ( " " input ) ; debug ! ( " " String from_utf8_lossy ( req ) ) ; child_stdin . write ( & req ) . await ? ; std :: mem :: drop ( child_stdin ) ; let _status = child . await ? ; let mut res = Vec :: new ( ) ; child_stdout . read_to_end ( & mut res ) . await ? ; debug ! ( " " String from_utf8_lossy ( res ) ) ; let output : Output < Request :: Response > = serde_json :: from_slice ( & res ) ? ; info ! ( " " output ) ; // TODO: use semver for more lenient version compatibility if output . version ( ) != VERSION { failure :: bail ! ( " " ) ; } output . into_inner ( ) . map_err ( | e | failure :: err_msg ( format ! ( " " e ) ) ) }
Send a Request to the plugin, blocking until the plugin returns some
Output.
Send a Request to the plugin blocking until the plugin returns some Output .
&self
request
Request
&self
request
Request