Expose code conversion methods on SqlState
This commit is contained in:
parent
41bcb71176
commit
72a7544bee
10
src/error.rs
10
src/error.rs
@ -25,13 +25,21 @@ macro_rules! make_errors {
|
|||||||
);
|
);
|
||||||
|
|
||||||
impl SqlState {
|
impl SqlState {
|
||||||
#[doc(hidden)]
|
/// Creates a `SqlState` from its error code.
|
||||||
pub fn from_code(s: String) -> SqlState {
|
pub fn from_code(s: String) -> SqlState {
|
||||||
match STATE_MAP.get(&*s) {
|
match STATE_MAP.get(&*s) {
|
||||||
Some(state) => state.clone(),
|
Some(state) => state.clone(),
|
||||||
None => SqlState::Unknown(s)
|
None => SqlState::Unknown(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the error code corresponding to the `SqlState`.
|
||||||
|
pub fn code(&self) -> &str {
|
||||||
|
match *self {
|
||||||
|
$(SqlState::$error => $code,)+
|
||||||
|
SqlState::Unknown(ref s) => &**s,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user