pub mod proto {
#![allow(clippy::derive_partial_eq_without_eq)]
include!(concat!(env!("OUT_DIR"), "/ya_runtime_api.rs"));
impl response::Error {
pub fn msg<D: std::fmt::Display>(msg: D) -> Self {
let mut e = Self::default();
e.set_code(response::ErrorCode::Internal);
e.message = msg.to_string();
e
}
}
}
mod codec;
#[cfg(feature = "codec")]
pub use codec::Codec;
pub use proto::request::{CreateNetwork, KillProcess, RunProcess};
pub use proto::response::create_network::Endpoint as NetworkEndpoint;
pub use proto::response::runtime_status::Counter as RuntimeCounter;
pub use proto::response::runtime_status::Kind as RuntimeStatusKind;
pub use proto::response::runtime_status::State as RuntimeState;
pub use proto::response::CreateNetwork as CreateNetworkResp;
pub use proto::response::Error as ErrorResponse;
pub use proto::response::RunProcess as RunProcessResp;
pub use proto::response::{ErrorCode, ProcessStatus, RuntimeStatus};
pub use proto::{Network, NetworkInterface};
use futures::future::{BoxFuture, LocalBoxFuture};
use futures::prelude::*;
use std::process::{ExitStatus, Stdio};
use std::sync::Arc;
use tokio::process;
pub type AsyncResponse<'a, T> = LocalBoxFuture<'a, Result<T, ErrorResponse>>;
pub trait RuntimeService {
fn hello(&self, version: &str) -> AsyncResponse<'_, String>;
fn run_process(&self, run: RunProcess) -> AsyncResponse<'_, RunProcessResp>;
fn kill_process(&self, kill: KillProcess) -> AsyncResponse<'_, ()>;
fn create_network(&self, network: CreateNetwork) -> AsyncResponse<'_, CreateNetworkResp>;
fn shutdown(&self) -> AsyncResponse<'_, ()>;
}
pub trait RuntimeHandler {
fn on_process_status<'a>(&self, status: ProcessStatus) -> BoxFuture<'a, ()>;
fn on_runtime_status<'a>(&self, status: RuntimeStatus) -> BoxFuture<'a, ()>;
}
pub trait RuntimeControl {
fn id(&self) -> u32;
fn stop(&self);
fn stopped(&self) -> BoxFuture<'_, i32>;
}
mod client;
mod service;
pub use client::spawn;
pub use service::{run, run_async};