Simplify AsRenderElements::render_elements<C>()
#1626
Replies: 2 comments 3 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.
-
|
Hi all, (sorry for bumping old thread) I wonder what if rather than returning a It lets the implementation to just reuse Thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current definition (A) is the following:
IIUC, the intention of the parameter is reducing
memcpyingVec. Consider the following case:Here, conversion is done at (3) (from
HogeRenderElementstoFooRenderElements::Hoge) and (2) (fromFooRenderElementstoOutputRenderElements::Hoge)as
<Output as AsRenderElements>::render_elements()is called withC = OutputRenderElements. ButmemcpyingVecmight 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).
memcpying is done at (3), (2), (1).But, in real applications, we can't expect the reduce.
For example,
OutputRenderElementsis 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