1use sys::*;
2
3#[derive(Debug)]
5#[must_use]
6pub enum Return<T, E = ()> {
7 Success(T),
9 Info(T),
11 Error(E),
13}
14pub use Return::{Error, Info, Success};
15
16impl<T, E> Return<T, E> {
17 pub fn map<F, U>(self, f: F) -> Return<U, E>
20 where
21 F: FnOnce(T) -> U,
22 {
23 match self {
24 Success(v) => Success(f(v)),
25 Info(v) => Info(f(v)),
26 Error(e) => Error(e),
27 }
28 }
29
30 pub fn map_error<F, U>(self, f: F) -> Return<T, U>
33 where
34 F: FnOnce(E) -> U,
35 {
36 match self {
37 Success(v) => Success(v),
38 Info(v) => Info(v),
39 Error(e) => Error(f(e)),
40 }
41 }
42
43 pub fn unwrap(self) -> T {
45 match self {
46 Success(v) | Info(v) => v,
47 Error(_) => {
48 panic!("Unwrapping `Return` failed. Use diagnostics to obtain more information.")
49 }
50 }
51 }
52
53 pub fn success<U>(self) -> Result<T, U>
56 where
57 U: From<E>,
58 {
59 match self {
60 Success(v) | Info(v) => Ok(v),
61 Error(e) => Err(e.into()),
62 }
63 }
64}
65
66impl From<SQLRETURN> for Return<()> {
67 fn from(source: SQLRETURN) -> Return<()> {
68 match source {
69 SQL_SUCCESS => Success(()),
70 SQL_SUCCESS_WITH_INFO => Info(()),
71 SQL_ERROR => Error(()),
72 other => panic!("Unexpected SQLRETURN value: {:?}", other),
73 }
74 }
75}