Skip to content

Minimal support for the optional generic children#189

Open
XX wants to merge 3 commits intovidhanio:svgfrom
XX:optional_generic_children
Open

Minimal support for the optional generic children#189
XX wants to merge 3 commits intovidhanio:svgfrom
XX:optional_generic_children

Conversation

@XX
Copy link
Contributor

@XX XX commented Mar 11, 2026

This PR adds minimal support to component builders for optional children with generic type (such as R: Renderable and Lazy<F> where F: Fn(&mut Buffer)). Unlike using the type Lazy<fn(&mut Buffer)>, these generic types can capture environment variables. Using Option also allows creating a component both with explicitly specified children and without them.

The general idea of the solution is that the builder method is implemented only for a specific children type where this field is set to None. When the children setter method is called, the previous type is replaced with a new one corresponding to the children provided at the call site.

This PR introduces some helper mechanisms for Builder and DefaultBuilder that allow users to combine them with manually implemented methods specific to converting children types. Some manual work is still required, but it could be minimized in the future.

dependabot bot and others added 3 commits March 10, 2026 16:55
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Stefanos Apostolopoulos <stefanos@retinai.com>
Co-authored-by: Vidhan Bhatt <me@vidhan.io>
@vidhanio
Copy link
Owner

@XX looks interesting, thank you! Could you instead base the PR on the svg branch? There is a large-ish refactor there.

@vidhanio vidhanio changed the base branch from main to svg March 12, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants