I am trying to make a iterator like pattern (or builder pattern might be more accurate).
Where I want to have a core function which will pass in bytes through the rest of the chain, and each part of the chain would decode it into a specific struct, using a structs decode function, I want it so I can override a part of this chain in a way that makes sense, something like, at compile time it detects if a generic associated with a part of a chain matches with a generic associated with some later part of the chain, it will override or extend the original part of the chain
so like
foo().chain::<Test>(|..| ...).chain::<Test>(|..| ...)
the first chain is overridden or the first chain itself is extended by the second part of it (because Test is used across both)
The reason why is i am working on a library which provides a default chain where it decodes into various structs, and when something is decoded I would rather it be re-used rather than re-decoding the same thing somewhere down the chain.
so what's your question?
a "chain" is just a bunch of composable function calls arranged so that the data are passed from left to right, which is easier for humans to read. it is not just used in builder pattern and iterator adapters. it is also commonly referred as "pipelines", akin to the "pipe" operator in shells and functional languages like F#.
note, sometimes people use the term UFCS, e.g. C++ P3021, but I try to avoid it. the meaning of the word "universal" is, ironically, not universally agreed on, so different people may use it for different things. e.g. in rust, we have this rfc132 which use the same term for complete different concept. the syntax in the rfc is still relevant today, but the term ufcs is not actively used.
if you understand function composition, you understand method chaining.it's like playing "tetris" with types: given a function f that goes from type A to type B, and a function g that goes from B to C, you can compose them to get a function g ∘ f which goes from A to C.
if you already have some functions with matching signatures, rust already has the machinary to convert them into a pipeline: extension traits and blanket implementations. the crate tap implements many common chaining wrapper, you can check it out