diesel/query_dsl/
join_dsl.rs
1use crate::helper_types;
2use crate::query_builder::AsQuery;
3use crate::query_source::joins::OnClauseWrapper;
4use crate::query_source::{JoinTo, QuerySource, Table};
5
6#[doc(hidden)]
7pub trait InternalJoinDsl<Rhs, Kind, On> {
9 type Output;
10
11 fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output;
12}
13
14impl<T, Rhs, Kind, On> InternalJoinDsl<Rhs, Kind, On> for T
15where
16 T: Table + AsQuery,
17 T::Query: InternalJoinDsl<Rhs, Kind, On>,
18{
19 type Output = <T::Query as InternalJoinDsl<Rhs, Kind, On>>::Output;
20
21 fn join(self, rhs: Rhs, kind: Kind, on: On) -> Self::Output {
22 self.as_query().join(rhs, kind, on)
23 }
24}
25
26#[doc(hidden)]
27pub trait JoinWithImplicitOnClause<Rhs, Kind> {
30 type Output;
31
32 fn join_with_implicit_on_clause(self, rhs: Rhs, kind: Kind) -> Self::Output;
33}
34
35impl<Lhs, Rhs, Kind> JoinWithImplicitOnClause<Rhs, Kind> for Lhs
36where
37 Lhs: JoinTo<Rhs>,
38 Lhs: InternalJoinDsl<<Lhs as JoinTo<Rhs>>::FromClause, Kind, <Lhs as JoinTo<Rhs>>::OnClause>,
39{
40 type Output = <Lhs as InternalJoinDsl<Lhs::FromClause, Kind, Lhs::OnClause>>::Output;
41
42 fn join_with_implicit_on_clause(self, rhs: Rhs, kind: Kind) -> Self::Output {
43 let (from, on) = Lhs::join_target(rhs);
44 self.join(from, kind, on)
45 }
46}
47
48pub trait JoinOnDsl: Sized {
75 fn on<On>(self, on: On) -> helper_types::On<Self, On> {
77 OnClauseWrapper::new(self, on)
78 }
79}
80
81impl<T: QuerySource> JoinOnDsl for T {}