use super::{Channel, CrateType, Edition, Mode};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ExecuteRequest<'a> {
pub channel: Channel,
pub mode: Mode,
pub edition: Edition,
#[serde(rename = "crateType")]
pub crate_type: CrateType,
pub tests: bool,
#[serde(default)]
pub backtrace: bool,
pub code: Cow<'a, str>,
}
impl<'a> ExecuteRequest<'a> {
pub fn new(
channel: Channel,
mode: Mode,
edition: Edition,
crate_type: CrateType,
tests: bool,
backtrace: bool,
code: Cow<'a, str>,
) -> Self {
Self {
channel,
mode,
edition,
crate_type,
tests,
backtrace,
code,
}
}
}
impl<'b> super::Request for ExecuteRequest<'b> {
fn endpoint<'a>(&self) -> super::Endpoints<'a> {
super::Endpoints::Execute
}
}
impl<'a> Default for ExecuteRequest<'a> {
fn default() -> Self {
Self {
channel: Channel::Stable,
mode: Mode::Debug,
edition: Edition::Edition2024,
crate_type: CrateType::Binary,
tests: false,
backtrace: false,
code: Cow::Borrowed("fn main() { println!(\"Hello, world!\"); }"),
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct ExecuteResponse<'a> {
pub success: bool,
#[serde(rename = "exitDetail")]
pub exit_detail: Cow<'a, str>,
pub stdout: Cow<'a, str>,
pub stderr: Cow<'a, str>,
}
impl<'a> super::Response for ExecuteResponse<'a> {}