exedev 0.1.0

Official Rust SDK for exe.dev: create VMs, run commands on them, and run every exe.dev command
Documentation
// Code generated by "go run ./cmd/gensdkrs" in the exe.dev repository. DO NOT EDIT.

//! Blocking calls, for programs without an async runtime: with the
//! `blocking` feature, [`BlockOn::block_on`] runs any of the SDK's requests
//! to completion on a runtime the SDK starts once and shares.
//!
//! ```no_run
//! use exedev::blocking::BlockOn as _;
//!
//! # fn main() -> exedev::Result<()> {
//! let exe = exedev::Client::from_env()?;
//! let vm = exe.new_vm().block_on()?;
//! let result = vm.run("uname -a").block_on()?;
//! print!("{}", result.stdout_lossy());
//! vm.delete().block_on()?;
//! # Ok(()) }
//! ```
//!
//! Do not call it from async code, which should `.await` instead: it panics
//! inside a Tokio runtime.

use std::future::IntoFuture;
use std::sync::OnceLock;

fn runtime() -> &'static tokio::runtime::Runtime {
    static RUNTIME: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
    RUNTIME.get_or_init(|| {
        tokio::runtime::Builder::new_multi_thread()
            .worker_threads(2)
            .thread_name("exedev")
            .enable_all()
            .build()
            .expect("exedev: cannot start a Tokio runtime")
    })
}

/// Runs a request, or any future, to completion, blocking the thread.
pub trait BlockOn: IntoFuture {
    /// Runs it to completion, and returns its output.
    fn block_on(self) -> Self::Output;
}

impl<F: IntoFuture> BlockOn for F {
    fn block_on(self) -> Self::Output {
        runtime().block_on(self.into_future())
    }
}