1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::database::Database;
use crate::decode::Decode;
use crate::types::HasSqlType;
pub trait RowIndex<R: ?Sized>
where
R: Row,
{
fn try_get<T>(&self, row: &R) -> crate::Result<T>
where
R::Database: HasSqlType<T>,
T: Decode<R::Database>;
}
pub trait Row: Unpin + Send + 'static {
type Database: Database + ?Sized;
fn is_empty(&self) -> bool {
self.len() == 0
}
fn len(&self) -> usize;
fn get<T, I>(&self, index: I) -> T
where
Self::Database: HasSqlType<T>,
I: RowIndex<Self>,
T: Decode<Self::Database>;
}
pub trait FromRow<R>
where
R: Row,
{
fn from_row(row: R) -> Self;
}
#[allow(unused_macros)]
macro_rules! impl_from_row_for_row {
($R:ty) => {
impl crate::row::FromRow<$R> for $R {
#[inline]
fn from_row(row: $R) -> Self {
row
}
}
};
}