cosoc
1
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Test{
pub a: Option<String>,
pub b: Option<String>,
pub c: Option<String>,
pub d: Option<String>,
pub e: Option<String>,
}
new a struct
let s = Test {
a = Some(String::from("have a vlue"))
b = None,
c = None,
d = None,
e = None,
}
Is there a simplified writing method ?
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
// ^^^^^^^
pub struct Test {
pub a: Option<String>,
pub b: Option<String>,
pub c: Option<String>,
pub d: Option<String>,
pub e: Option<String>,
}
fn main() {
let _s = Test {
a: Some(String::from("have a vlue")),
..Default::default()
// ^^^^^^^^^^^^^^^^^^^^
};
}
Playground.
See also.
2 Likes
system
Closed
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.