I have a use case where I want to transition from one struct type into another, moving data to the new place. My guess is that no copy should be involved since I just transfer ownership of fields, though I am a little puzzled about how new struct will be able to build it's memory layout without copying?
struct Topic {
pub name: String,
pub topic: String
}
#[derive(Debug)]
struct IndexedTopic {
index: u32,
name: String,
topic: String
}
impl Topic {
pub fn index(self, index: u32) -> IndexedTopic {
IndexedTopic {
name: self.name,
topic: self.topic,
index
}
}
}
fn main() {
let topic = Topic { name: "foo".to_owned(), topic: "bar".to_owned() };
dbg!(topic.index(1));
}