fpagliughi / rust-industrial-io

Rust interface to the Linux Industrial I/O subsystem
MIT License
45 stars 21 forks source link

WIP: Make use of iterators for printing data in the examples #11

Closed Funky185540 closed 3 years ago

Funky185540 commented 3 years ago

Hi,

I'm currently learning about the power of iterators in Rust, and I thought I'd give it a go with the for-loop that prints the results in the examples. I have only "converted" one example for the time being.

I'd really like to hear your thoughts about it!

If you think that it's okay, I can adapt the other examples, too.

Cheers, Andreas

fpagliughi commented 3 years ago

I do it both ways depending on what is being done in the specific algorithm; specifically for which seems more readable. Half the times I don't think about it, one way or the other seems natural from the start.

I'm not sure this is specifically more readable for the particular instance (though my original for loop might be improved).

But the idea for examples in a library like this is to show possible different ways to do things with the library to help a new user along. So, on that note, I would think that we apply this PR, but leave the other examples as they are, to show both ways for doing this.

Oh, keep in mind, too that a "for" loop uses the iterator, too!

Funky185540 commented 3 years ago

I'm not sure this is specifically more readable for the particular instance

That is of course a good point. Personally I didn't understand what iterators do until I read the chapter in the Rust book, but now I think it's pretty neat!

Oh, keep in mind, too that a "for" loop uses the iterator, too!

Yes indeed! So much to consider... :)