Add a lightweight version written with declarative macros #2
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 a lightweight version of crate_interface.
Motivation
The major reason for crate_interface_lite is the same as pin-project-lite -- using declarative macros does not require any external dependencies and could speed up the fresh builds (that is building from scratch with crate_interface requires compiling proc-macro related crates beforehand). Also, for potential library authors use this crate, crate_interface_lite would result in a tidier dependency tree of their projects.
Implementation
Due to the limitations of declarative macros, the lite one lacks supports for complex ASTs. And I have documented perceptible differences1.
Furthermore,
crate_interface_lite::def_interface
uses a different approach to work withcall_interface
. Instead of generating a privatemod
to include linkedextern fn
s2, it implements the defined interface for a dummy struct, as illustrated below:This should be transparent for users, since the implementation details are not exposed to them.
Future works
If you accept this PR, I would like to take the responsibility for the future maintenance of crate_interface_lite :)
Footnotes
Though some of them could be resolved, but it would complicate the internal macro parsing procedure. ↩
This is actually impossible for declarative macros unless
concat_idents
is stable. ↩