News for hackers. Stuff that matters.
Re:Common Rust Lifetime Misconceptions by mikekchar on Saturday May 23, 2020 @09:53AM (#23282940)
Generally speaking, I've found Rust terminology confusing. For example, why does the `IntoIter` iterator gives you owned values? What the heck does "Into" mean to a Rust developer? There are lots of things like that. I've found that fluency in Rust is partly trying to understand the concepts and partly just learning to understand the specific meanings of certain vocabulary. I've likened it to working with Ruby on Rails. There are a lot of useful facilities, but they practically force you to think exactly like the original author -- who doesn't seem to quite speak like I do.
Re:Common Rust Lifetime Misconceptions by ReactiveJelly on Saturday May 23, 2020 @11:46AM (#23283858)
"Into" means it turns the Vec _into_ an iterator.

Normally an iterator iterates _over_ a Vec or other collection, without moving or destroying the Vec.

There's also iter_mut which iterates over the Vec but allows you to mutate elements in-place.

Those are the 3 big groups of iterators: Immutable, mutable, and the ones that consume (i.e. destroy) the vector.

Re:Common Rust Lifetime Misconceptions by mikekchar on Saturday May 23, 2020 @09:29PM (#23288267)
I think the thing is that because the IntoIter consumes the collection, you are right that it is turning it "into" an iterator... I guess. But for me that's not the intent of what I'm doing. If I use iter() or mut_iter(), I'm also getting an iterator. The fact that it doesn't consume the collection is not the thing I care about. I don't program thinking "Oh, I want to consume this collection when I create the iterator, so let's use into_iter()". I think, "Oh, I want to get owned objects out of the iterator. As a side effect of that, it will consume the collection". For me, anyway, it's just a seriously backwards way of saying what you want.

I find that, similar to my experience with Rails (and Rails developers), once you've drunk the Kool aide, it starts to make sense. You are fluent in the language that is being used and you can't think any other way about it. Even if it is awkward, it seems normal and obvious. But when you first approach it, it can be hard to acquire the idea.

Re:Common Rust Lifetime Misconceptions by wtetzner on Wednesday May 27, 2020 @11:39AM (#23324928)
I could see that. It was a little confusing to me too. At first I couldn't figure out why anyone would want into_iter(). Didn't realize it returned owned objects.

Now that I think about it, how does into_iter() work on a Vec? Is it just copying the data out of the Vec anyway? Because the data in a Vec is allocated on the heap, so how can you get an owned object that isn't just a reference (pointer) to the heap memory without copying?

If that's the case, is the only benefit of into_iter() that you don't have to explicitly deref and copy the items?

Re:Common Rust Lifetime Misconceptions by littlestymaar on Saturday May 23, 2020 @11:17AM (#23283609)
> What the heck does "Into" mean to a Rust developer?

Into means it will consume the value (you don't have it anymore): https://doc.rust-lang.org/1.0.0/style/style/naming/conversio...

Re:Common Rust Lifetime Misconceptions by steveklabnik on Saturday May 23, 2020 @11:22AM (#23283643)
(Please note this document is outdated; you’ve linked to the 1.0.0 docs. This particular page is pretty ok but we don’t ship this at all anymore, and haven’t for years.)
Re:Common Rust Lifetime Misconceptions by ChrisSD on Saturday May 23, 2020 @11:49AM (#23283895)
I think the maintained equivalent would be in the Rust API guidelines:

https://rust-lang.github.io/api-guidelines/naming.html#ad-ho...