Is there a way to print the values of x and y here.
Obviously println!("{}", x); gives E0277 errors.
'''
#![feature(box_syntax)]
struct BigStruct {
one: i32,
two: i32,
// etc
one_hundred: i32,
}
fn foo(x: Box) -> BigStruct {
*x
}
fn main() {
let x = Box::new(BigStruct {
one: 1,
two: 2,
one_hundred: 100,
});
let y: Box<BigStruct> = box foo(x);
}
'''
pixel
2
I think all you need to do is define Debug:
#[derive(Debug)]
struct BigStruct {
one: i32,
two: i32,
// etc
one_hundred: i32,
}
Then use :? in the println.
println!("{:?}", y);
At the bottom.
That worked, Thanks - was even able to manipulate the box values adhoc - so what matters is the return value for i32.
#![feature(box_syntax)]
#[derive(Debug)]
struct BigStruct {
one: i32,
two: i32,
// etc
one_hundred: i32,
}
fn foo(x: Box<BigStruct>) -> BigStruct {
*x
}
fn main() {
let x = Box::new(BigStruct {
one: 1 + 1,
two: 2 + 2,
one_hundred: 100 + 100,
});
let y: Box<BigStruct> = box foo(x);
println!("Here is the value of y: ");
println!("{:?}", y);
}
Here is the value of y:
BigStruct { one: 2, two: 4, one_hundred: 200 }