blob: 49b99398940d957d162e490a37976b2332860a15 (
plain) (
blame)
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
37
38
39
40
41
42
|
use mingling::{
Groupped,
macros::{r_println, renderer},
};
use serde::Serialize;
use crate::ThisProgram;
#[derive(Groupped)]
pub struct IOError {
inner: std::io::Error,
}
impl IOError {
pub fn new(error: std::io::Error) -> Self {
Self { inner: error }
}
}
impl From<std::io::Error> for IOError {
fn from(error: std::io::Error) -> Self {
Self::new(error)
}
}
impl Serialize for IOError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
let mut state = serializer.serialize_struct("IOError", 2)?;
state.serialize_field("kind", &self.inner.kind().to_string())?;
state.serialize_field("info", &self.inner.to_string())?;
state.end()
}
}
#[renderer]
pub fn render_io_error(prev: IOError) {
r_println!("{}: {}", prev.inner.kind(), prev.inner.to_string())
}
|