improve builder pattern according to #20#30
improve builder pattern according to #20#30tchamelot wants to merge 4 commits intocopterust:masterfrom
Conversation
little-arhat
left a comment
There was a problem hiding this comment.
LGTM!
It would be nice to maybe update dmp example to show how to use new builders.
FYI, this branch increases size of a mpu code, compiled in release mode by 100bytes (according to cargo bloat):
with status quo version:
0.1% 1.3% 538B mpu9250
with this branch:
0.1% 1.6% 686B mpu9250
Not a huge increase, but maybe worth tracking that down to confirm increase is coming from useful functions.
Thanks!
|
|
||
| #[cfg(not(feature = "i2c"))] | ||
| /// Build new Mpu9250 from current configuration using the provided device | ||
| pub fn build<E, SPI, NCS>(self, |
There was a problem hiding this comment.
For SPI connected devices we also provide *_with_reinit family of constructors. Although they are a bit ugly, they serve practical need -- maybe worth adding support for reinit to builders?
There was a problem hiding this comment.
Could you give me an example of how you would use *with_reinit() so I can try to design something ergonomic.
I did not know about cargo bloat, so i gave it a try on the rpi example.
First of all, the size of the mpu9250 crate is much bigger in my case. I do not see any change between this branch and the master when using the legacy init system. However, there is a 0.1KiB increase when using the new init system based on the builder pattern. I can add it in the readme or in the doc if you think that such a small amount of memory should be documented. |
Hey, this is a proposition to improve the builder pattern. It does not break the previous building method.
Now, one is able to build an instance with
or
If you have any suggestion, I will be glad to ear about it!