How does for loop implement into_iter

Follow up this question which is marked as duplicate as question here. The concept of how for loop implement into_iter keeps haunt me down and this answer kinda creates more question to me like the terms of re-borrow, which is not mentioned in rust official document at all except in one place. To my understanding… Read More How does for loop implement into_iter

`#[derive(Clone)]` seems to wrongfully enforce generic to be `clone`

It seems that when deriving Clone, Rust forwards the Clone trait requirement to Generics that do not require the trait, like if they are wrapped inside an Arc. Do I misunderstand how Clone works or is this a compiler mistake? Consider the following code, where a.clone() works, but b.clone() does not. Also note that without… Read More `#[derive(Clone)]` seems to wrongfully enforce generic to be `clone`

Tuple struct to function coercion : what are the lifetime parameters of said function?

I don’t understand something about the feature that makes it possible to coerce a tuple struct to a function as in: struct MyType(u8); let optional_mytype: Option<MyType> = Some(12).map(MyType); // ^^^^^^ here, MyType is treated as a function In the example above, no lifetimes are involved: everything is easy. However, when the structure has a generic… Read More Tuple struct to function coercion : what are the lifetime parameters of said function?

Why can't a mutable method be called on a mutable String reference but works for TcpStream

As I was trying to understand the differences between a mutable variable, which happens to be a reference, e.g. let mut x: &i32 vs mutable references, e.g. let x: &mut i32, I found this difference I can’t understand: This works, where by_ref has the signature: fn by_ref(&mut self) -> &mut Self (docs) fn example(mut t:… Read More Why can't a mutable method be called on a mutable String reference but works for TcpStream