Is there a way to initialize a buffer on the heap without first initializing it on the stack and then moving it on to the heap?
pub struct Agent {
name: String,
designation: String,
age: u8
}
pub fn stalloc() {
let s = Agent {
name: "frank".into(),
designation: "006".into(),
age: 37
};
let h = Box::new(s);
}
It would be nice if Rust has special plumbing to realize that the stack object isn't actually needed, so it could move the initialization into Box::new() and perform it just after the allocation. I realize this isn't feasible, but is there some other mechanism through which it is possible? Out of historical curiosity -- could Rust's old box keyword do this?