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
use sys::*;
#[derive(Debug)]
#[must_use]
pub enum ReturnOption<T, E = ()> {
Success(T),
Info(T),
NoData(E),
Error(E),
}
impl<T, E> ReturnOption<T, E> {
pub fn map<F, U>(self, f: F) -> ReturnOption<U, E>
where
F: FnOnce(T) -> U,
{
match self {
ReturnOption::Success(t) => ReturnOption::Success(f(t)),
ReturnOption::Info(t) => ReturnOption::Info(f(t)),
ReturnOption::NoData(e) => ReturnOption::NoData(e),
ReturnOption::Error(e) => ReturnOption::Error(e),
}
}
}
impl From<SQLRETURN> for ReturnOption<()> {
fn from(source: SQLRETURN) -> ReturnOption<()> {
match source {
SQL_SUCCESS => ReturnOption::Success(()),
SQL_SUCCESS_WITH_INFO => ReturnOption::Info(()),
SQL_ERROR => ReturnOption::Error(()),
SQL_NO_DATA => ReturnOption::NoData(()),
other => panic!("Unexpected SQLRETURN value: {:?}", other),
}
}
}