Minimal support for the optional generic children#189
Open
XX wants to merge 3 commits intovidhanio:svgfrom
Open
Minimal support for the optional generic children#189XX wants to merge 3 commits intovidhanio:svgfrom
XX wants to merge 3 commits intovidhanio:svgfrom
Conversation
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>
Owner
|
@XX looks interesting, thank you! Could you instead base the PR on the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds minimal support to component builders for optional children with generic type (such as
R: RenderableandLazy<F> where F: Fn(&mut Buffer)). Unlike using the typeLazy<fn(&mut Buffer)>, these generic types can capture environment variables. UsingOptionalso allows creating a component both with explicitly specified children and without them.The general idea of the solution is that the
buildermethod is implemented only for a specific children type where this field is set toNone. When thechildrensetter 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
BuilderandDefaultBuilderthat 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.