use std::fmt;
use crate::RustLibPath;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RustLibFile {
pub path: RustLibPath,
pub contents: String,
}
impl RustLibFile {
pub fn new(path: RustLibPath, contents: impl Into<String>) -> Self {
Self {
path,
contents: contents.into(),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RustLibDocs {
pub version: String,
pub documentation: String,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CheckStage {
Fetch,
Format,
Build,
Clippy,
Test,
DocTest,
}
impl CheckStage {
pub fn as_str(self) -> &'static str {
match self {
Self::Fetch => "fetch",
Self::Format => "format",
Self::Build => "build",
Self::Clippy => "clippy",
Self::Test => "test",
Self::DocTest => "doc-test",
}
}
}
impl fmt::Display for CheckStage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CheckStageResult {
pub stage: CheckStage,
pub success: bool,
pub exit_code: Option<i32>,
pub stdout: String,
pub stderr: String,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CheckResult {
pub stages: Vec<CheckStageResult>,
}
impl CheckResult {
pub fn passed(&self) -> bool {
self.stages.len() == 6 && self.stages.iter().all(|stage| stage.success)
}
pub fn failure(&self) -> Option<&CheckStageResult> {
self.stages.iter().find(|stage| !stage.success)
}
}