Having all this code in a macro has numerous disadvantages: - The code is less readable, as you often have to jump between the code itself and the arguments passed into the macro. - The code is deeply indented, and the macro can sometime confuse the syntax highlighting, both of which exacerbate the readability problem. - Any compiler error in the macro shows up multiple times, for each implementation that the macro generates. - Multiple nearly identical methods are generated. I haven't checked whether the affects the size of the compiled binary, but even if the compiler is smart enough to optimize this, why not unify the common code into one method. I'm sure there are more, but this is what I can think of off the top of my head. This commit replaces the big-macro approach with the following: - The bulk of the code is moved out of the macro. - The out-of-macro code is made generic over the USART instance. - A trait is implemented for all USART instances, which abstracts over the differences between them. - The implementations of this traits are the last thing left in the macro. I realize this breaks with tradition, but for the reasons mentioned, I think this approach is superior to the classic "everything in the macro" approach. There's also prior art in the nrf-rs and lpc-rs worlds.  https://github.com/nrf-rs/  https://github.com/lpc-rs/
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.