Simplify AsRenderElements::render_elements<C>()
#1626
kenoss
started this conversation in
API Design
Replies: 1 comment 2 replies
-
I am pretty sure @cmeissl I personally always envisioned the trait to look like (C), any obvious concerns with that approach? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The current definition (A) is the following:
IIUC, the intention of the parameter is reducing
memcpy
ingVec
. Consider the following case:Here, conversion is done at (3) (from
HogeRenderElements
toFooRenderElements::Hoge
) and (2) (fromFooRenderElements
toOutputRenderElements::Hoge
)as
<Output as AsRenderElements>::render_elements()
is called withC = OutputRenderElements
. Butmemcpy
ingVec
might also occur in (1) as we use.into_iter().map(C::from).collect::<Vec<_>>()
.("Might" means it might vanish with optimization.)
Consider the following trait definition (B) instead:
Then, conversion is done at (2), and (1).
memcpy
ing is done at (3), (2), (1).But, in real applications, we can't expect the reduce.
For example,
OutputRenderElements
is constructed with multiple sources in Anvil [code].We can consider yet another definition (C):
The chaining pattern like
xs.into_iter().map(|x| x.into()).chain(ys.into_iter().map(|y| y.into()))
is very common like the above example in applications built on top of smithay.This should make code very simple and intuitive.
I prefer (C) > (B) > (A). WDYT? Let me know if you know the reason why the current implementation is using (A).
Beta Was this translation helpful? Give feedback.
All reactions