4 #![feature(rustc_private)]
6 extern crate rustc_serialize;
8 use rustc_serialize::{Encodable, Decodable};
11 pub trait Entity : Decodable + Encodable + Sized {
12 type Key: Clone + Decodable + Encodable + ToString + Display + Eq + Ord + Sized;
14 fn id(&self) -> Self::Key;
16 fn find_by_id(id: Self::Key) -> Option<Self>;
19 pub struct DbRef<E: Entity> {
23 impl<E> DbRef<E> where E: Entity {
24 fn get(self) -> Option<E> {
25 E::find_by_id(self.id)