use super::*;
pub trait PresetContract {
type Output;
const REQUIRED_PARTS: &'static [&'static str];
}
pub trait PartsContract {
type Output;
const PROVIDED_PARTS: &'static [&'static str];
}
pub struct NoPreset;
impl PresetContract for NoPreset {
type Output = ();
const REQUIRED_PARTS: &'static [&'static str] = &[];
}
pub struct NoParts;
impl PartsContract for NoParts {
type Output = ();
const PROVIDED_PARTS: &'static [&'static str] = &[];
}
pub const fn assert_contract<P, T>()
where
P: PresetContract,
T: PartsContract<Output = P::Output>,
{
}
impl ObjectContract {
pub fn into_owned(self) -> OwnedObjectContract {
OwnedObjectContract {
required_parts: self
.required_parts
.iter()
.map(|value| (*value).to_owned())
.collect(),
provided_parts: self
.provided_parts
.iter()
.map(|value| (*value).to_owned())
.collect(),
}
}
pub fn validate(&self, object: &str) -> Vec<String> {
validate_object_contract(self.required_parts, self.provided_parts, object)
}
}
#[derive(Clone, Copy, Debug)]
pub struct ObjectContract {
pub required_parts: &'static [&'static str],
pub provided_parts: &'static [&'static str],
}