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