cc3200-rs icon indicating copy to clipboard operation
cc3200-rs copied to clipboard

Add getchar and helpers @dhylands @fabricedesre

Open tdz opened this issue 8 years ago • 9 comments

tdz avatar Nov 08 '16 15:11 tdz

I guess you did it this way to not create strings on the heap but instead reuse the same buffer? That is clearly not idiomatic Rust, let me think how we could achieve the same goals with less unsafe calls.

fabricedesre avatar Nov 08 '16 19:11 fabricedesre

In MicroPython we have the traditional pythonic read method which always allocates a new string, and then we also support read_into, where the caller provides a pointer and length and then no allocations are required. For rust we could provde a mutable slice (which is effectively a pointer and length).

dhylands avatar Nov 08 '16 19:11 dhylands

Here's my take on the read_into option: https://play.rust-lang.org/?gist=8bb5c89db3491cc01eb303804ef7b3f4&version=stable&backtrace=0

fabricedesre avatar Nov 08 '16 21:11 fabricedesre

Your for loop should be 0.. rather than 1..

dhylands avatar Nov 08 '16 21:11 dhylands

And something else isn't quite right. If you fill buf with 0x45 ('E') then I don't get the expected results. https://gist.github.com/584a6c649c07200175d2c4f3793c4f4a

dhylands avatar Nov 08 '16 21:11 dhylands

no, because the [u8] length doesn't know about the terminating 0

fabricedesre avatar Nov 08 '16 21:11 fabricedesre

ha you're right 0 .. N loops to 0 to N-1. I though it was inclusive. The other error is more interesting!

fabricedesre avatar Nov 08 '16 21:11 fabricedesre

Hm, indeed it's not doing the right thing... see https://play.rust-lang.org/?gist=0091cfe93c016259b158a4a4fa6306eb&version=stable&backtrace=0

fabricedesre avatar Nov 08 '16 21:11 fabricedesre

Thanks for the comments. Sorry, I'm still learning how to do this in Rust.

tdz avatar Nov 09 '16 15:11 tdz