News for hackers. Stuff that matters.
Re:Learning Rust with ChatGPT, Copilot and Advent of Code by dv_dt on Monday December 05, 2022 @06:02PM (#33873172)
On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator.

I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quickly verifiable.

Re:Learning Rust with ChatGPT, Copilot and Advent of Code by simonw on Monday December 05, 2022 @06:07PM (#33873237)
When I asked it how to undo an operation I had performed using "cargo add" it confidently showed me examples of using the "cargo remove" command... which it had entirely made up.
Re:Learning Rust with ChatGPT, Copilot and Advent of Code by nerpderp82 on Monday December 05, 2022 @06:27PM (#33873452)
ChatGPT is on nightly of course, https://doc.rust-lang.org/nightly/cargo/commands/cargo-remov...

It should have told you `cargo +nightly remove <dep>`

Re:Learning Rust with ChatGPT, Copilot and Advent of Code by Ygg2 on Monday December 05, 2022 @06:19PM (#33873359)
There is chunk operator on std::slice.

How would that work on general iterators? You can have an iterator that always returns 'y'. Or buffered iteration or whatever.

Re:Learning Rust with ChatGPT, Copilot and Advent of Code by tialaramex on Monday December 05, 2022 @06:28PM (#33873471)
See for yourself:

https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...

As the parent said, it's not stable yet but it's right there so you can see how it works.

The most important ergonomic trick here is that Rust has type inference, it can see array_chunks needs to know how big the chunks should be, and of course you can just specify that but in most cases you'll use chunks which clearly have a defined size and the inference will go "Oh, that's how big the chunks are" just as e.g. if you put a bunch of chars in a Vec you made, the type inference goes, "Oh, it's a Vec of chars" and doesn't waste your time asking you what type of Vec it is.

You'll see the example expects Some(['l', 'o']) to be the first thing out of the Iterator, the type inference system can see that's an array of two chars, thus, the chunk size is 2.

Re:Learning Rust with ChatGPT, Copilot and Advent of Code by Ygg2 on Monday December 05, 2022 @07:20PM (#33874026)
Yeah, but does seem to function bit different than chunks. Plus it's unstable and as expected has perf issues.

It being nightly doesn't mean it will be stabilized.