Skip to content

Commit d65df55

Browse files
committed
Type hack
1 parent 841bd33 commit d65df55

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

src/connection/cursor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use types::{NativeSqlType, FromSqlRow};
44

55
use std::marker::PhantomData;
66

7-
pub struct Cursor<ST, T> {
7+
pub struct Cursor<ST, T, Hack = ()> {
88
current_row: usize,
99
db_result: DbResult,
10-
_marker: PhantomData<(ST, T)>,
10+
_marker: PhantomData<(ST, T, Hack)>,
1111
}
1212

13-
impl<ST, T> Cursor<ST, T> {
13+
impl<ST, T, Hack> Cursor<ST, T, Hack> {
1414
pub fn new(db_result: DbResult) -> Self {
1515
Cursor {
1616
current_row: 0,
@@ -20,9 +20,9 @@ impl<ST, T> Cursor<ST, T> {
2020
}
2121
}
2222

23-
impl<ST, T> Iterator for Cursor<ST, T> where
23+
impl<ST, T, Hack> Iterator for Cursor<ST, T, Hack> where
2424
ST: NativeSqlType,
25-
T: Queriable<ST>,
25+
T: Queriable<ST, Hack>,
2626
{
2727
type Item = T;
2828

src/connection/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ impl Connection {
4747
self.query_all(source).map(|mut e| e.nth(0))
4848
}
4949

50-
pub fn query_all<T, U>(&self, source: &T) -> Result<Cursor<T::SqlType, U>> where
50+
pub fn query_all<T, U, Hack>(&self, source: &T) -> Result<Cursor<T::SqlType, U, Hack>> where
5151
T: QuerySource,
52-
U: Queriable<T::SqlType>,
52+
U: Queriable<T::SqlType, Hack>,
5353
{
5454
let sql = self.prepare_query(source);
5555
self.query_sql(&sql)
5656
}
5757

58-
pub fn query_sql<T, U>(&self, query: &str) -> Result<Cursor<T, U>> where
58+
pub fn query_sql<T, U, Hack>(&self, query: &str) -> Result<Cursor<T, U, Hack>> where
5959
T: NativeSqlType,
60-
U: Queriable<T>,
60+
U: Queriable<T, Hack>,
6161
{
6262
let result = try!(self.execute_inner(query));
6363
Ok(Cursor::new(result))

src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ macro_rules! joinable_inner {
180180
}
181181
}
182182

183+
#[macro_export]
183184
macro_rules! belongs_to {
184185
($parent:ty, $parent_table:ident, $child:ty, $child_table:ident) => {
185-
impl $crate::Queriable<($child_table::SqlType, $parent_table::SqlType)>
186+
impl $crate::Queriable<($child_table::SqlType, $parent_table::SqlType), $parent>
186187
for ($child, $parent) {
187188
type Row = (
188189
<$child as $crate::Queriable<$child_table::SqlType>>::Row,

src/query_source/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use self::select::SelectSqlQuerySource;
88

99
pub use self::joins::JoinTo;
1010

11-
pub trait Queriable<ST: NativeSqlType> {
11+
pub trait Queriable<ST: NativeSqlType, Hack = ()> {
1212
type Row: FromSqlRow<ST>;
1313

1414
fn build(row: Self::Row) -> Self;

tests/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn pg_array_containing_null() {
119119

120120
fn query_single_value<T: NativeSqlType, U: Queriable<T>>(sql: &str) -> U {
121121
let connection = connection();
122-
let mut cursor = connection.query_sql::<T, U>(sql)
122+
let mut cursor = connection.query_sql::<T, U, _>(sql)
123123
.unwrap();
124124
cursor.nth(0).unwrap()
125125
}

0 commit comments

Comments
 (0)