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
36
use std::fmt::Display;
use crate::ColumnType;
#[derive(Debug)]
pub struct FbError {
pub msg: String,
pub code: i32,
}
impl Display for FbError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}: {}", self.code, self.msg)
}
}
impl std::error::Error for FbError {}
pub fn err_column_null(type_name: &str) -> FbError {
FbError {
code: -1,
msg: format!(
"This is a null value. Use the Option<{}> to safe access this column and avoid errors",
type_name
),
}
}
pub fn err_type_conv<T>(from: ColumnType, to: &str) -> Result<T, FbError> {
Err(FbError {
code: -1,
msg: format!("Can't convert {:?} column to {}", from, to),
})
}