use crate::delegate::delegate_shape_except_named;
use alux_shape::{FieldAlg, ShapeAlg, Words};
#[derive(Debug, Clone, Copy, Default)]
pub struct Patch<A>(pub A);
impl<A> Patch<A> {
fn inner(&self) -> &A {
&self.0
}
}
impl<A> Patch<A>
where
A: ShapeAlg,
{
fn rename(&self, words: Words<'_>, body: A::Ty) -> A::Ty {
let mut named: Vec<&str> = words.to_vec();
named.push("patch");
self.inner().named(&named, body)
}
}
delegate_shape_except_named!(Patch);
impl<A> FieldAlg for Patch<A>
where
A: ShapeAlg + FieldAlg,
{
fn field(&self, words: Words<'_>, shape: A::Ty) -> A::Field {
self.inner().field(words, self.inner().opt(shape))
}
fn merge(&self, shape: A::Ty) -> A::Field {
self.inner().merge(shape)
}
}