2 #![feature(rustc_private)]
4 extern crate serialize;
6 use serialize::{Encodable, Decodable};
9 pub trait Entity : Decodable + Encodable + Sized {
10 type Key: Clone + Decodable + Encodable + ToString + Display + Eq + Ord + Sized;
12 fn id(&self) -> Self::Key;
14 fn find_by_id(id: Self::Key) -> Option<Self>;
17 pub struct DbRef<E: Entity> {
21 impl<E> DbRef<E> where E: Entity {
22 fn get(self) -> Option<E> {
23 E::find_by_id(self.id)