Skip to content

Commit 72a7544

Browse files
committed
Expose code conversion methods on SqlState
1 parent 41bcb71 commit 72a7544

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/error.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ macro_rules! make_errors {
2525
);
2626

2727
impl SqlState {
28-
#[doc(hidden)]
28+
/// Creates a `SqlState` from its error code.
2929
pub fn from_code(s: String) -> SqlState {
3030
match STATE_MAP.get(&*s) {
3131
Some(state) => state.clone(),
3232
None => SqlState::Unknown(s)
3333
}
3434
}
35+
36+
/// Returns the error code corresponding to the `SqlState`.
37+
pub fn code(&self) -> &str {
38+
match *self {
39+
$(SqlState::$error => $code,)+
40+
SqlState::Unknown(ref s) => &**s,
41+
}
42+
}
3543
}
3644
)
3745
}

0 commit comments

Comments
 (0)