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
use crateConversionError;
/// Converts the given database value into a specific rust type.
///
/// We recommend to implement `try_into` as gracefully as possible, i.e.,
/// supporting as many conversions as possible. For the numeric
/// types this requires some lines of code, but the effort pays off for the users.
///
/// Example:
///
/// ```rust,ignore
/// impl DbValueInto<u32> for MyDbValue {
/// fn try_into(self) -> Result<u32, ConversionError> {
/// match self {
/// MyDbValue::TINYINT(u) => Ok(u as u32),
///
/// MyDbValue::SMALLINT(i) => if i >= 0 {
/// Ok(i as u32)
/// } else {
/// Err(ConversionError::NumberRange(...))
/// }
///
/// MyDbValue::INT(i) => if i >= 0 {
/// Ok(i as u32)
/// } else {
/// Err(ConversionError::NumberRange(...))
/// }
///
/// MyDbValue::BIGINT(i) => if (i >= 0) && (i <= u32::MAX as i64) {
/// Ok(i as u32)
/// } else {
/// Err(ConversionError::NumberRange(...))
/// }
///
/// _ => Err(ConversionError::ValueType(...)),
/// }
/// }
/// }
/// ```