@@ -5,15 +5,22 @@ use std::io;
5
5
use std:: ops:: Range ;
6
6
7
7
use stmt:: Column ;
8
+ use rows:: sealed:: Sealed ;
8
9
9
- /// A trait implemented by types that can index into columns of a row.
10
- pub trait RowIndex {
11
- /// Returns the index of the appropriate column, or `None` if no such
12
- /// column exists.
13
- fn idx ( & self , stmt : & [ Column ] ) -> Option < usize > ;
10
+ mod sealed {
11
+ use stmt:: Column ;
12
+
13
+ pub trait Sealed {
14
+ fn idx ( & self , stmt : & [ Column ] ) -> Option < usize > ;
15
+ }
14
16
}
15
17
16
- impl RowIndex for usize {
18
+ /// A trait implemented by types that can index into columns of a row.
19
+ ///
20
+ /// This cannot be implemented outside of this crate.
21
+ pub trait RowIndex : Sealed { }
22
+
23
+ impl Sealed for usize {
17
24
#[ inline]
18
25
fn idx ( & self , stmt : & [ Column ] ) -> Option < usize > {
19
26
if * self >= stmt. len ( ) {
@@ -24,7 +31,9 @@ impl RowIndex for usize {
24
31
}
25
32
}
26
33
27
- impl < ' a > RowIndex for str {
34
+ impl RowIndex for usize { }
35
+
36
+ impl Sealed for str {
28
37
#[ inline]
29
38
fn idx ( & self , stmt : & [ Column ] ) -> Option < usize > {
30
39
if let Some ( idx) = stmt. iter ( ) . position ( |d| d. name ( ) == self ) {
@@ -40,16 +49,24 @@ impl<'a> RowIndex for str {
40
49
}
41
50
}
42
51
43
- impl < ' a , T : ?Sized > RowIndex for & ' a T
52
+ impl RowIndex for str { }
53
+
54
+ impl < ' a , T > Sealed for & ' a T
44
55
where
45
- T : RowIndex ,
56
+ T : ? Sized + Sealed ,
46
57
{
47
58
#[ inline]
48
59
fn idx ( & self , columns : & [ Column ] ) -> Option < usize > {
49
60
T :: idx ( * self , columns)
50
61
}
51
62
}
52
63
64
+ impl < ' a , T > RowIndex for & ' a T
65
+ where
66
+ T : ?Sized + Sealed ,
67
+ {
68
+ }
69
+
53
70
#[ doc( hidden) ]
54
71
pub struct RowData {
55
72
body : DataRowBody ,
0 commit comments