Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 03940a8

Browse files
committed
Merge pull request #67 from ville-h/24972
24972
2 parents 215c867 + 342ba47 commit 03940a8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/24972.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use rustc_serialize::{Encodable, Decodable};
2+
use std::fmt::Display;
3+
4+
5+
pub trait Entity : Decodable + Encodable + Sized {
6+
type Key: Clone + Decodable + Encodable + ToString + Display + Eq + Ord + Sized;
7+
8+
fn id(&self) -> Self::Key;
9+
10+
fn find_by_id(id: Self::Key) -> Option<Self>;
11+
}
12+
13+
pub struct DbRef<E: Entity> {
14+
pub id: E::Key,
15+
}
16+
17+
impl<E> DbRef<E>
18+
where E: Entity {
19+
fn get(self) -> Option<E> {
20+
E::find_by_id(self.id)
21+
}
22+
}

0 commit comments

Comments
 (0)