1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! The `Default` trait for types which may have meaningful default values
15 /// A trait that types which have a useful default value should implement.
17 /// Return the "default value" for a type.
22 /// use std::default::Default;
24 /// let i: i8 = Default::default();
25 /// let (x, y): (Option<String>, f64) = Default::default();
26 /// let (a, b, (c, d)): (int, uint, (bool, bool)) = Default::default();
31 macro_rules! default_impl(
35 fn default() -> $t { $v }
41 default_impl!(bool, false)
42 default_impl!(char, '\x00')
44 default_impl!(uint, 0u)
45 default_impl!(u8, 0u8)
46 default_impl!(u16, 0u16)
47 default_impl!(u32, 0u32)
48 default_impl!(u64, 0u64)
50 default_impl!(int, 0i)
51 default_impl!(i8, 0i8)
52 default_impl!(i16, 0i16)
53 default_impl!(i32, 0i32)
54 default_impl!(i64, 0i64)
56 default_impl!(f32, 0.0f32)
57 default_impl!(f64, 0.0f64)