Skip to content

Commit

Permalink
Add HeapSizeOf support.
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Oct 25, 2015
1 parent fb6ce0a commit 89b7fcd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ keywords = ["mime", "media-extensions", "media-types"]
[dependencies]
log = "*"

[dependencies.heapsize]
version = "0.1.1"
optional = true

[dependencies.heapsize_plugin]
version = "0.1.0"
optional = true

[features]
nightly = []
heap_size = ["heapsize", "heapsize_plugin"]
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(all(feature = "nightly", test), feature(test))]

#![cfg_attr(feature = "heap_size", feature(plugin, custom_derive))]
#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))]

#[cfg(feature = "heap_size")] extern crate heapsize;

#[macro_use]
extern crate log;

Expand Down Expand Up @@ -113,14 +118,34 @@ macro_rules! __mime__ident_or_ext {
)
}

macro_rules! enoom {
// This is a workaround, because cfg_attr() isn't working right inside a macro.
#[cfg(feature = "heap_size")]
macro_rules! enoom_derive_type {
(pub enum $en:ident; $ext:ident; $($ty:ident, $text:expr;)*) => (

#[derive(Clone, Debug, HeapSizeOf)]
pub enum $en {
$($ty),*,
$ext(String)
}
)
}
#[cfg(not(feature = "heap_size"))]
macro_rules! enoom_derive_type {
(pub enum $en:ident; $ext:ident; $($ty:ident, $text:expr;)*) => (

#[derive(Clone, Debug)]
pub enum $en {
$($ty),*,
$ext(String)
}
)
}

macro_rules! enoom {
(pub enum $en:ident; $ext:ident; $($ty:ident, $text:expr;)*) => (

enoom_derive_type!(pub enum $en; $ext; $($ty, $text;)*);

impl $en {
pub fn as_str(&self) -> &str {
Expand Down

0 comments on commit 89b7fcd

Please sign in to comment.