diff options
Diffstat (limited to 'components')
-rw-r--r-- | components/macros/lib.rs | 63 | ||||
-rw-r--r-- | components/style/Cargo.toml | 2 | ||||
-rw-r--r-- | components/style/lib.rs | 4 | ||||
-rw-r--r-- | components/style/properties/mod.rs.mako | 2 |
4 files changed, 5 insertions, 66 deletions
diff --git a/components/macros/lib.rs b/components/macros/lib.rs index daf5eb3c52c..b8db24baea1 100644 --- a/components/macros/lib.rs +++ b/components/macros/lib.rs @@ -184,66 +184,3 @@ macro_rules! bitfield( } ) ) - - -#[macro_export] -macro_rules! lazy_init( - ($(static ref $N:ident : $T:ty = $e:expr;)*) => ( - $( - #[allow(non_camel_case_types)] - struct $N {__unit__: ()} - static $N: $N = $N {__unit__: ()}; - impl Deref<$T> for $N { - fn deref<'a>(&'a self) -> &'a $T { - unsafe { - static mut s: *const $T = 0 as *const $T; - static mut ONCE: ::sync::one::Once = ::sync::one::ONCE_INIT; - ONCE.doit(|| { - s = ::std::mem::transmute::<Box<$T>, *const $T>(box () ($e)); - }); - &*s - } - } - } - - )* - ) -) - - -#[cfg(test)] -mod tests { - use std::collections::hashmap::HashMap; - lazy_init! { - static ref NUMBER: uint = times_two(3); - static ref VEC: [Box<uint>, ..3] = [box 1, box 2, box 3]; - static ref OWNED_STRING: String = "hello".to_string(); - static ref HASHMAP: HashMap<uint, &'static str> = { - let mut m = HashMap::new(); - m.insert(0u, "abc"); - m.insert(1, "def"); - m.insert(2, "ghi"); - m - }; - } - - fn times_two(n: uint) -> uint { - n * 2 - } - - #[test] - fn test_basic() { - assert_eq!(*OWNED_STRING, "hello".to_string()); - assert_eq!(*NUMBER, 6); - assert!(HASHMAP.find(&1).is_some()); - assert!(HASHMAP.find(&3).is_none()); - assert_eq!(VEC.as_slice(), &[box 1, box 2, box 3]); - } - - #[test] - fn test_repeat() { - assert_eq!(*NUMBER, 6); - assert_eq!(*NUMBER, 6); - assert_eq!(*NUMBER, 6); - } -} diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index a8ccfc42e35..38964c0e4da 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -29,3 +29,5 @@ git = "https://github.com/servo/rust-cssparser" [dependencies.encoding] git = "https://github.com/lifthrasiir/rust-encoding" +[dependencies.lazy_static] +git = "https://github.com/Kimundi/lazy-static.rs" diff --git a/components/style/lib.rs b/components/style/lib.rs index 412c7f142a2..05b358eec70 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -22,9 +22,9 @@ extern crate url; extern crate cssparser; extern crate encoding; - #[phase(plugin)] -extern crate "macros" as servo_macros; +extern crate lazy_static; + extern crate "util" as servo_util; diff --git a/components/style/properties/mod.rs.mako b/components/style/properties/mod.rs.mako index 0befa50158c..a38c7568ca0 100644 --- a/components/style/properties/mod.rs.mako +++ b/components/style/properties/mod.rs.mako @@ -1822,7 +1822,7 @@ fn get_writing_mode(inheritedbox_style: &style_structs::InheritedBox) -> Writing /// The initial values for all style structs as defined by the specification. -lazy_init! { +lazy_static! { static ref INITIAL_VALUES: ComputedValues = ComputedValues { % for style_struct in STYLE_STRUCTS: ${style_struct.ident}: Arc::new(style_structs::${style_struct.name} { |