Joe232
March 20, 2023, 6:55am
1
Say if I wanted to save Object
:
struct Object
{
rect: Rect,
square: Square,
rectangular_prism: RectangularPrism,
}
struct Rect
{
x: u32,
y: u32,
}
struct Square
{
x: u32,
y: u32,
}
struct RectangularPrism
{
x: u32,
y: u32,
z: u32,
}
fn main()
{
}
fn save(object: &Object)
{
let data = match postcard::to_stdvec(object)
{
Ok(d) => d,
Err(e) => {println!("Error on save: {e}"); return;}
};
}
Would this save with complex data structures and to even load from the postcard file easily?
Add #[derive(Serialize, Deserialize)]
on every struct used in the value in question, and you should be fine, unless there's something you aren't telling us which makes the explicitly documented way not work.
Joe232
March 20, 2023, 7:11am
3
ah yeah I forgot to add that, but how would I load from the file?
But I am not entirely sure what to type for something more complex such as my exanple?
Is it some complicated code?
H2CO3
March 20, 2023, 9:33am
4
Serde handles all serializeable/deserializeable types in exactly the same way.
No, it is as trivial as it gets. They have an example in the official documentation . It's exactly what you would expect.
1 Like
system
Closed
June 18, 2023, 9:34am
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.