tank_core/query/
as_query.rs1use crate::{Driver, DynQuery, Query, RawQuery};
2
3pub trait AsQuery<D: Driver> {
4 type Output: AsMut<Query<D>> + Send;
5 fn as_query(self) -> Self::Output;
6}
7
8impl<D: Driver> AsQuery<D> for Query<D> {
9 type Output = Query<D>;
10 fn as_query(self) -> Self::Output {
11 self
12 }
13}
14
15impl<'q, D: Driver + 'q> AsQuery<D> for &'q mut Query<D> {
16 type Output = &'q mut Query<D>;
17 fn as_query(self) -> Self::Output {
18 self
19 }
20}
21
22impl<D: Driver> AsQuery<D> for DynQuery {
23 type Output = Query<D>;
24 fn as_query(self) -> Self::Output {
25 match self {
26 DynQuery::Raw(v) => Query::Raw(v),
27 DynQuery::Prepared(p) => match p.as_any().downcast::<D::Prepared>() {
28 Ok(p) => Query::Prepared(*p),
29 Err(..) => Query::raw(Default::default()),
30 },
31 }
32 }
33}
34
35impl<D: Driver> AsQuery<D> for RawQuery {
36 type Output = Query<D>;
37 fn as_query(self) -> Self::Output {
38 Query::Raw(self)
39 }
40}
41
42impl<D: Driver> AsQuery<D> for String {
43 type Output = Query<D>;
44 fn as_query(self) -> Self::Output {
45 Query::raw(self)
46 }
47}
48
49impl<D: Driver> AsQuery<D> for &str {
50 type Output = Query<D>;
51 fn as_query(self) -> Self::Output {
52 Query::raw(self.into())
53 }
54}