use std::intrinsics::TypeId;
use GenericEvent;
use ptr::Ptr;
pub trait TextEvent {
fn from_text(text: &str) -> Option<Self>;
fn text<U>(&self, f: |&str| -> U) -> Option<U>;
}
impl<T: GenericEvent> TextEvent for T {
#[inline(always)]
fn from_text(text: &str) -> Option<T> {
let id = TypeId::of::<Box<TextEvent>>();
Ptr::with_str::<Option<T>>(text, |ptr| {
GenericEvent::from_event(id, ptr)
})
}
#[inline(always)]
fn text<U>(&self, f: |&str| -> U) -> Option<U> {
let id = TypeId::of::<Box<TextEvent>>();
self.with_event(id, |ptr| {
f(ptr.expect_str())
})
}
}