Skip to content

Instantly share code, notes, and snippets.

@matthewjberger
Created August 21, 2024 03:38
Show Gist options
  • Save matthewjberger/7ec7cfd002f1b8134ad3e86eaeedc2f7 to your computer and use it in GitHub Desktop.
Save matthewjberger/7ec7cfd002f1b8134ad3e86eaeedc2f7 to your computer and use it in GitHub Desktop.
serde_json error impl From<> in rust
impl From<serde_json::Error> for Error {
fn from(value: serde_json::Error) -> Self {
let class = match value.classify() {
serde_json::error::Category::Io => "io",
serde_json::error::Category::Syntax => "syntax",
serde_json::error::Category::Data => "data",
serde_json::error::Category::Eof => "eof",
};
Error::Deser {
class: class.to_string(),
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment