1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use core::ffi::c_int;
use core::fmt;
use core::ops::Add;
/// Defines a parameter index for binding values to a statement.
///
/// This hides the implementation detail for traits which reference an index.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Index {
raw: c_int,
}
impl Index {
/// The first index used when binding parameters into a [`Statement`].
///
/// This is useful when implementing [`Bind`] for a primitive type which
/// implements [`BindValue`].
///
/// [`Statement`]: crate::Statement
/// [`Bind`]: crate::Bind
/// [`BindValue`]: crate::BindValue
pub const BIND: Self = Self::from_raw(1);
/// Construct an index from its raw representation.
#[inline]
pub const fn from_raw(raw: c_int) -> Self {
Self { raw }
}
#[inline]
pub(crate) const fn raw(&self) -> c_int {
self.raw
}
}
/// Add implementation for [`Index`] to allow incrementing the index.
impl Add<usize> for Index {
type Output = Self;
#[inline]
fn add(self, rhs: usize) -> Self::Output {
Index {
raw: self.raw + rhs as c_int,
}
}
}
impl fmt::Debug for Index {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.raw.fmt(f)
}
}