Take ownership of pins instead of mutable borrows
Closed this issue · 3 comments
The use of &mut ref for gpio and clk pins makes it difficult to use this crate in any way other than creating pin instances as local variables in main (as you show in your example code).
I want to hold pins and tm1637 in a struct, using the struct impl to create the pins and instantiate the tm1637 instead of doing it in main. Because you have mutable refs for the pins, it is difficult to do this. I've tried various ugly ways to do this without success (There may be a way, but I haven't found it). I'm now thinking of rewriting your code to take ownership of the pins
Is there a reason why you have used &mut
for the clk and dio pins, rather than taking ownership?
Well, there's actually no much reason at all, coz, this is just one of my first tries to use Rust)
To be honest I researched over the Internet but didn't happen to figure out how "take ownership" would be better than the current approach. So, it would be great if you outline your idea in code (a draft).
Anyway, you're welcome to open a PR.
Well, I must apologize. I didn't understand the issue properly. Please feel free to close it.
I forked your repository, and changed the tm1637 code to use moves for clk and dio. But when I came to use it, I had the same problem in creating clk and dio, behind mutable references. all that did is highlight that the hal uses mutable borrows for pins. So it didn't solve the issue.
I'll have to work out another way to get what I want.
Yeah, HAL needs mutable refs.
When you'll figure out a more convenient way to use the code, please, lemme know.