...but I really don't know how to do it. I've tried various times here, but without success. Is it possible? If not, is there any (idiomatic) way to do anything like this?
In safe Rust a structure cannot exist in a half-uninitialized state, so your new() must produce a full, complete structure, or at least initialize all fields to some default/placeholder values.
One option is to require all input before the object is created:
To simplify initialization of structures Rust has Default trait and Struct {..default_values} syntax. You can implement Default trait for your structure.
With #[derive(Default)] you can use a built-in Default implementation, which makes everything 0:
I've already tested the fn (other_value: i64) method, but sometimes the user can add nothing as the "V2" value, so I wanted an option that allows the user to simply ignore the "V2" and use a placeholder value to be filled on another function. Using a already-placed value seemed as a "unnecessary overhead" at runtime, since all the data on the struct will be filled by a user or by the program itself (Ok, probably rustc can optimize it, but...).
However, using ..Default::default() worked without problems. Thank you very much, and sorry for taking so long to answer back. Here's my code, with some testing of ..Default::default():
Ok, just one more question: Is there a way to modify more than one value of the struct? (I've tried using ..Default::default() on "V3", but it didn't work (the value tried to modify remained "0").
I've forgotten of it. But I've added this just for testing, because I want to modify more than one struct without repeating "Anything.". I know that I can do anything like this: