Skip to content

Commit

Permalink
Adding Default::default()
Browse files Browse the repository at this point in the history
  • Loading branch information
simsekgokhan committed Apr 23, 2024
1 parent b60c85f commit 1ad36df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[derive(Debug, Default, PartialEq)]
struct Foo {
x: i32,
// d: chrono::Date<chrono::Utc>,
// If a field is no Default, Foo definition itself will cause error.
// err: the trait `Default` is not implemented for `Date<Utc>
s: String,
w: Option<bool>,
y: i32,
}

#[test]
fn ex1() {
let foo = Foo { x: 42, y: 33, ..Default::default() };
assert_eq!(foo, Foo { x: 42, s: "".to_string(), w: None, y: 33 });

let foo: Foo = Default::default();
assert_eq!(foo, Foo { x: 0, s: "".to_string(), w: None, y: 0 });
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod ctor_chain;
mod compile_vs_runtime_read_env_and_file;
mod concurrency;
mod const_fn;
mod default;
mod drop_aka_dtor;
mod r#enum;
mod env_logger;
Expand Down

0 comments on commit 1ad36df

Please sign in to comment.