use serde::{Deserialize, Serialize};
use crate::project::ProjectResult;
pub const VERSION: u32 = 1;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BatchResult {
pub focus: Option<ProjectResult>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub full: Option<ProjectResult>,
pub manifest_sha256: String,
pub compiler_invocations: u64,
pub batched: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub selection_error: Option<crate::output::ErrorInfo>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub engine_fault: Option<crate::output::ErrorInfo>,
}
impl BatchResult {
#[must_use]
pub fn accepted(&self) -> bool {
self.full
.as_ref()
.is_some_and(|full| self.accepted_with(full))
}
#[must_use]
pub fn accepted_with(&self, full: &ProjectResult) -> bool {
self.selection_error.is_none() && self.engine_fault.is_none() && accepted(full)
}
}
#[must_use]
pub fn accepted(full: &ProjectResult) -> bool {
crate::acceptance::complete_selection(full).is_some()
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Selection {
pub package: String,
pub target: Option<String>,
pub kind: String,
pub function: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Submission {
pub verification: crate::jobs::Submission,
pub selection: Selection,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResultDocument {
pub version: u32,
pub batch: BatchResult,
pub accepted: bool,
}
impl From<BatchResult> for ResultDocument {
fn from(batch: BatchResult) -> Self {
Self {
version: VERSION,
accepted: batch.accepted(),
batch,
}
}
}