serde-yaml
serde-yaml copied to clipboard
Is there a way to get `ErrorKind` ?
Hi, there.
use serde::Deserialize;
use std::{fs, io::ErrorKind};
fn main() {
#[derive(Deserialize)]
struct One {
_one: Option<bool>,
_two: Option<bool>,
}
if let Err(e) = fs::read_to_string("jqoifnjiosdj") {
match e.kind() {
ErrorKind::NotFound => println!("is ok"),
_ => println!("no, is not ok"),
}
}
if let Err(e) = serde_yaml::from_str::<One>("") {
// match e.kind() {}
println!("this is not ok: {}", e);
}
if serde_yaml::from_str::<One>("something:").is_ok() {
println!("this is ok");
}
}
Is there a way to get the error kind like std::io::ErrorKind
? I want ignore empty input, use default in this case, but I can't get the error kind.
As of new versions of serde_yaml I think your program just does what you want.
is ok
this is ok