use crate::Target;
use crate::buildpack::Buildpack;
use crate::{data::build_plan::BuildPlan, data::buildpack::ComponentBuildpackDescriptor};
use std::fmt::Debug;
use std::path::PathBuf;
pub struct DetectContext<B: Buildpack + ?Sized> {
pub app_dir: PathBuf,
pub buildpack_dir: PathBuf,
pub target: Target,
pub platform: B::Platform,
pub buildpack_descriptor: ComponentBuildpackDescriptor<B::Metadata>,
}
#[derive(Debug)]
#[must_use]
pub struct DetectResult(pub(crate) InnerDetectResult);
#[derive(Debug)]
pub(crate) enum InnerDetectResult {
Fail,
Pass { build_plan: Option<BuildPlan> },
}
#[must_use]
pub struct DetectResultBuilder;
impl DetectResultBuilder {
pub fn pass() -> PassDetectResultBuilder {
PassDetectResultBuilder { build_plan: None }
}
pub fn fail() -> FailDetectResultBuilder {
FailDetectResultBuilder {}
}
}
#[must_use]
pub struct PassDetectResultBuilder {
build_plan: Option<BuildPlan>,
}
impl PassDetectResultBuilder {
pub fn build<E>(self) -> Result<DetectResult, E> {
Ok(self.build_unwrapped())
}
pub fn build_unwrapped(self) -> DetectResult {
DetectResult(InnerDetectResult::Pass {
build_plan: self.build_plan,
})
}
pub fn build_plan(mut self, build_plan: BuildPlan) -> Self {
self.build_plan = Some(build_plan);
self
}
}
#[must_use]
pub struct FailDetectResultBuilder;
impl FailDetectResultBuilder {
pub fn build<E>(self) -> Result<DetectResult, E> {
Ok(self.build_unwrapped())
}
#[allow(clippy::unused_self)]
pub fn build_unwrapped(self) -> DetectResult {
DetectResult(InnerDetectResult::Fail)
}
}