alux_shape_morph/
patch.rs1use crate::delegate::delegate_shape_except_named;
4use alux_shape::{FieldAlg, ShapeAlg, Words};
5
6#[derive(Debug, Clone, Copy, Default)]
11pub struct Patch<A>(pub A);
12
13impl<A> Patch<A> {
14 fn inner(&self) -> &A {
16 &self.0
17 }
18}
19
20impl<A> Patch<A>
21where
22 A: ShapeAlg,
23{
24 fn rename(&self, words: Words<'_>, body: A::Ty) -> A::Ty {
26 let mut named: Vec<&str> = words.to_vec();
27 named.push("patch");
28
29 self.inner().named(&named, body)
30 }
31}
32
33delegate_shape_except_named!(Patch);
34
35impl<A> FieldAlg for Patch<A>
36where
37 A: ShapeAlg + FieldAlg,
38{
39 fn field(&self, words: Words<'_>, shape: A::Ty) -> A::Field {
40 self.inner().field(words, self.inner().opt(shape))
42 }
43
44 fn merge(&self, shape: A::Ty) -> A::Field {
45 self.inner().merge(shape)
47 }
48}