diff --git a/.travis.yml b/.travis.yml index 02760d0..63f10e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ sudo: false language: rust +rust: nightly script: - cargo test - cargo clean diff --git a/examples/summarize-events/Cargo.toml b/examples/summarize-events/Cargo.toml index fc9e345..27d173f 100644 --- a/examples/summarize-events/Cargo.toml +++ b/examples/summarize-events/Cargo.toml @@ -10,3 +10,6 @@ rustc-serialize = "0" [dependencies.string_cache] path = "../.." + +[dependencies.string_cache_shared] +path = "../../shared" diff --git a/examples/summarize-events/src/main.rs b/examples/summarize-events/src/main.rs index 9da1445..db50fcd 100644 --- a/examples/summarize-events/src/main.rs +++ b/examples/summarize-events/src/main.rs @@ -7,17 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(core)] - extern crate csv; extern crate string_cache; +extern crate string_cache_shared; extern crate rustc_serialize; use string_cache::Atom; -use string_cache::atom::repr; use std::{env, cmp}; -use std::num::FromPrimitive; use std::collections::hash_map::{HashMap, Entry}; use std::path::Path; @@ -28,14 +25,32 @@ struct Event { string: Option, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FromPrimitive)] -#[repr(u8)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] enum Kind { Dynamic, Inline, Static, } +impl Kind { + fn from_tag(tag: u8) -> Kind { + match tag { + string_cache_shared::DYNAMIC_TAG => Kind::Dynamic, + string_cache_shared::INLINE_TAG => Kind::Inline, + string_cache_shared::STATIC_TAG => Kind::Static, + _ => panic!() + } + } + + fn to_tag(self) -> u8 { + match self { + Kind::Dynamic => string_cache_shared::DYNAMIC_TAG, + Kind::Inline => string_cache_shared::INLINE_TAG, + Kind::Static => string_cache_shared::STATIC_TAG, + } + } +} + #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] struct Summary { kind: Kind, @@ -62,10 +77,10 @@ fn main() { match &ev.event[..] { "intern" => { let tag = (ev.id & 0xf) as u8; - assert!(tag <= repr::STATIC_TAG); + assert!(tag <= string_cache_shared::STATIC_TAG); let string = match tag { - repr::DYNAMIC_TAG => dynamic[&ev.id].clone(), + string_cache_shared::DYNAMIC_TAG => dynamic[&ev.id].clone(), // FIXME: We really shouldn't be allowed to do this. It's a memory-safety // hazard; the field is only public for the atom!() macro. @@ -76,7 +91,7 @@ fn main() { Entry::Occupied(entry) => entry.into_mut().times += 1, Entry::Vacant(entry) => { entry.insert(Summary { - kind: FromPrimitive::from_u8(tag).unwrap(), + kind: Kind::from_tag(tag), times: 1, }); } @@ -118,14 +133,14 @@ fn main() { let mut by_kind = [0, 0, 0]; for &(_, Summary { kind, times }) in &summary { total += times; - by_kind[kind as usize] += times; + by_kind[kind.to_tag() as usize] += times; } println!("\n"); println!("kind times pct"); println!("------- ------- ----"); for (k, &n) in by_kind.iter().enumerate() { - let k: Kind = FromPrimitive::from_usize(k).unwrap(); + let k: Kind = Kind::from_tag(k as u8); print!("{:7?} {:7} {:4.1}", k, n, 100.0 * (n as f64) / (total as f64)); diff --git a/plugin/src/lib.rs b/plugin/src/lib.rs index 25bf327..b5136dd 100644 --- a/plugin/src/lib.rs +++ b/plugin/src/lib.rs @@ -10,7 +10,7 @@ #![crate_name="string_cache_plugin"] #![crate_type="dylib"] -#![feature(plugin_registrar, quote, box_syntax, static_assert)] +#![feature(plugin_registrar, quote, box_syntax)] #![feature(rustc_private, slice_patterns)] #![deny(warnings)] #![allow(unused_imports)] // for quotes diff --git a/shared/lib.rs b/shared/lib.rs index 432fbc4..6c5ce7d 100644 --- a/shared/lib.rs +++ b/shared/lib.rs @@ -11,7 +11,7 @@ //! the macros crate and the run-time library, in order to guarantee //! consistency. -#![feature(core, static_assert)] +#![feature(core)] #![deny(warnings)] use std::{mem, raw, intrinsics}; @@ -42,11 +42,9 @@ pub enum UnpackedAtom { const STATIC_SHIFT_BITS: usize = 32; +#[cfg(target_endian = "little")] // Not implemented yet for big-endian #[inline(always)] unsafe fn inline_atom_slice(x: &u64) -> raw::Slice { - #[static_assert] - const _IS_LITTLE_ENDIAN: bool = cfg!(target_endian = "little"); - let x: *const u64 = x; raw::Slice { data: (x as *const u8).offset(1), @@ -82,8 +80,7 @@ impl UnpackedAtom { #[inline(always)] pub unsafe fn from_packed(data: u64) -> UnpackedAtom { - #[static_assert] - const _DYNAMIC_IS_UNTAGGED: bool = DYNAMIC_TAG == 0; + debug_assert!(DYNAMIC_TAG == 0); // Dynamic is untagged match (data & 0xf) as u8 { DYNAMIC_TAG => Dynamic(data as *mut ()), diff --git a/src/lib.rs b/src/lib.rs index edc297d..34bb932 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ #![crate_name = "string_cache"] #![crate_type = "rlib"] -#![feature(plugin, unsafe_no_drop_flag, static_assert)] +#![feature(plugin, unsafe_no_drop_flag)] #![feature(core, collections, alloc, hash)] #![deny(warnings)] #![cfg_attr(test, feature(test))]