diff options
| author | bors <bors@rust-lang.org> | 2013-06-16 01:52:09 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-16 01:52:09 -0700 |
| commit | 08c1155a223eb79960e7a5dbb0ea6276ef9754ea (patch) | |
| tree | fdbb9cbe16c75d9cb615fc651a3946fb6391ed17 /src/test | |
| parent | d1927d295013e19e57a9773c37ded698e89392eb (diff) | |
| parent | 893c70d7bc670054ef646b71d4d503298cc50d76 (diff) | |
auto merge of #7142 : alexcrichton/rust/deriving-zero, r=pcwalton
This allows mass-initialization of large structs without having to specify all the fields. I'm a bit hesitant, but I wanted to get this out there. I don't really like using the `Zero` trait, because it doesn't really make sense for a type like `HashMap` to use `Zero` as the 'blank allocation' trait. In theory there'd be a new trait, but then that's adding cruft to the language which may not necessarily need to be there. I do think that this can be useful, but I only implemented `Zero` on the basic types where I thought it made sense, so it may not be all that usable yet. (opinions?)
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/deriving-zero.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/run-pass/deriving-zero.rs b/src/test/run-pass/deriving-zero.rs new file mode 100644 index 00000000000..2ee57624112 --- /dev/null +++ b/src/test/run-pass/deriving-zero.rs @@ -0,0 +1,40 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::util; +use std::num::Zero; + +#[deriving(Zero)] +struct A; +#[deriving(Zero)] +struct B(int); +#[deriving(Zero)] +struct C(int, int); +#[deriving(Zero)] +struct D { a: int } +#[deriving(Zero)] +struct E { a: int, b: int } + +#[deriving(Zero)] +struct Lots { + a: ~str, + b: @str, + c: Option<util::NonCopyable>, + d: u8, + e: char, + f: float, + g: (f32, char), + h: ~[util::NonCopyable], + i: @mut (int, int), +} + +fn main() { + assert!(Zero::zero::<Lots>().is_zero()); +} |
