Expose code conversion methods on SqlState

This commit is contained in:
Steven Fackler 2015-01-10 00:54:28 -08:00
parent 41bcb71176
commit 72a7544bee

View File

@ -25,13 +25,21 @@ macro_rules! make_errors {
);
impl SqlState {
#[doc(hidden)]
/// Creates a `SqlState` from its error code.
pub fn from_code(s: String) -> SqlState {
match STATE_MAP.get(&*s) {
Some(state) => state.clone(),
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,
}
}
}
)
}