fabricedesre / cc3200-rs

Getting Rust to run on a TI cc3200
Mozilla Public License 2.0
7 stars 2 forks source link

Add getchar and helpers @dhylands @fabricedesre #31

Open tdz opened 7 years ago

fabricedesre commented 7 years ago

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.

dhylands commented 7 years ago

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).

fabricedesre commented 7 years ago

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

dhylands commented 7 years ago

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

dhylands commented 7 years ago

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

fabricedesre commented 7 years ago

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

fabricedesre commented 7 years ago

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

fabricedesre commented 7 years ago

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

tdz commented 7 years ago

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