forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
35 lines (29 loc) 路 705 Bytes
/
Copy patherror.rs
File metadata and controls
35 lines (29 loc) 路 705 Bytes
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
use crate::error::DatabaseError;
use libsqlite3_sys::sqlite3_errstr;
use std::ffi::CStr;
use std::os::raw::c_int;
pub struct SqliteError {
#[allow(dead_code)]
code: c_int,
message: String,
}
impl SqliteError {
pub(crate) fn new(code: c_int) -> Self {
#[allow(unsafe_code)]
let message = unsafe {
let err = sqlite3_errstr(code);
debug_assert!(!err.is_null());
CStr::from_ptr(err)
};
Self {
code,
message: message.to_string_lossy().into_owned(),
}
}
}
impl DatabaseError for SqliteError {
fn message(&self) -> &str {
&self.message
}
}
impl_fmt_error!(SqliteError);