Cannot move out of borrowed content / cannot move out of behind a shared reference

Let’s look at the signature for into_bytes: fn into_bytes(self) -> Vec<u8> This takes self, not a reference to self (&self). That means that self will be consumed and won’t be available after the call. In its place, you get a Vec<u8>. The prefix into_ is a common way of denoting methods like this. I don’t … Read more

Why can’t I store a value and a reference to that value in the same struct?

Let’s look at a simple implementation of this: struct Parent { count: u32, } struct Child<‘a> { parent: &’a Parent, } struct Combined<‘a> { parent: Parent, child: Child<‘a>, } impl<‘a> Combined<‘a> { fn new() -> Self { let parent = Parent { count: 42 }; let child = Child { parent: &parent }; Combined { … Read more

tech