quaint_forked/connector/result_set/
index.rs

1use super::{ResultRow, ResultRowRef};
2use crate::ast::Value;
3use std::ops;
4
5pub trait ValueIndex<RowType, ReturnValue>: private::Sealed {
6    #[doc(hidden)]
7    fn index_into(self, row: &RowType) -> &ReturnValue;
8}
9
10mod private {
11    pub trait Sealed {}
12    impl Sealed for usize {}
13    impl Sealed for &str {}
14}
15
16impl ValueIndex<ResultRowRef<'_>, Value<'static>> for usize {
17    fn index_into<'v>(self, row: &'v ResultRowRef) -> &'v Value<'static> {
18        row.at(self).unwrap()
19    }
20}
21
22impl ValueIndex<ResultRowRef<'_>, Value<'static>> for &str {
23    fn index_into<'v>(self, row: &'v ResultRowRef) -> &'v Value<'static> {
24        row.get(self).unwrap()
25    }
26}
27
28impl ValueIndex<ResultRow, Value<'static>> for usize {
29    fn index_into(self, row: &ResultRow) -> &Value<'static> {
30        row.at(self).unwrap()
31    }
32}
33
34impl ValueIndex<ResultRow, Value<'static>> for &str {
35    fn index_into(self, row: &ResultRow) -> &Value<'static> {
36        row.get(self).unwrap()
37    }
38}
39
40impl<'a, I: ValueIndex<ResultRowRef<'a>, Value<'static>> + 'static> ops::Index<I> for ResultRowRef<'a> {
41    type Output = Value<'static>;
42
43    fn index(&self, index: I) -> &Value<'static> {
44        index.index_into(self)
45    }
46}
47
48impl<I: ValueIndex<ResultRow, Value<'static>> + 'static> ops::Index<I> for ResultRow {
49    type Output = Value<'static>;
50
51    fn index(&self, index: I) -> &Value<'static> {
52        index.index_into(self)
53    }
54}