【发布时间】:2021-01-09 12:48:54
【问题描述】:
我在我的 rust 项目中使用柴油和 postgres。
我现在正在努力解决的问题是,当我在表中插入时,可能会发生不同的错误,我想针对不同的错误类型采取不同的操作。
这些是错误: Diesel DatabaseErrorKind
我想做这样的事情(source):
use std::fs::File;
use std::io::ErrorKind;
fn main() {
let f = File::open("hello.txt");
let f = match f {
Ok(file) => file,
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
Ok(fc) => fc,
Err(e) => panic!("Problem creating the file: {:?}", e),
},
other_error => {
panic!("Problem opening the file: {:?}", other_error)
}
},
};
}
问题是柴油机错误没有error.kind()。
【问题讨论】:
标签: rust rust-diesel