Closed
Conversation
This is a non-generic writer that holds a type-erased pointer to a generic writer and is suitable for use in scenarios, such as runtime callbacks, where generic functions cannot be used. The approach taken here is a bit different from AnyReader in that the type-erased version has not replaced the generic version. Instead, an interface mixin is used to share the same interface between the two implementations.
Member
|
Duplicate of #17634 |
Contributor
Author
|
Alas, my inability to search has let me down once again. However, the approaches of the two PRs are quite different, so I'll leave this as-is for someone else to decide its fate. |
Contributor
|
should be closed now that #17634 is merged |
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 is a non-generic writer that holds a type-erased pointer to a generic writer and is suitable for use in scenarios, such as runtime callbacks, where generic functions cannot be used.
The approach taken here is a bit different from AnyReader in that the type-erased version has not replaced the generic version. Instead, an interface mixin is used to share the same interface between the two implementations.
Some additional thoughts:
std.iotest file. The test coverage here is pretty minimal since I didn't see a lot of other writer tests to be used as a template. This could be fleshed out.pub usingnamespacepattern for interface mixins is really nice and would like to see it used more instd. I think it's odd thatAnyReaderandGenericReaderimplement the same interface manually, butGenericReaderinternally creates anAnyReaderfor almost all of its methods. I am curious what the general opinion on this approach is.AnyWritercould have more methods in its vtable, which would reduce the number of function calls through pointers at the cost of additional code complexity. Since IO is expected to be orders of magnitude slower than a virtual call, I think it makes sense to keep the code simple. Also, maybe the optimizer is smart enough to optimize these out in many cases?