appcore 0.0.2

(Placeholder) Easy dev.
Documentation
use rustc_serialize::{Encodable, Decodable};
use std::fmt::Display;

pub trait Entity : Decodable + Encodable + Sized {
	type Key: Clone + Decodable + Encodable + ToString + Display + Eq + Ord + Sized;
	
	
	/// Get id of this entity.
	fn id(&self) -> Self::Key;
	
	/// Get model by id.
	fn find_by_id(id: Self::Key) -> Option<Self>;
	
	/// Generate a new key.
	fn generate_key() -> Self::Key;
}

pub struct DbRef<E: Entity> {
	/// Entity id
 	pub id: E::Key,
}

impl<E> DbRef<E>
 where E: Entity {
 	/// Get entity from reference.
	fn get(&self) -> Option<E> {
		E::find_by_id(&self.id)
	}
}