diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-16 21:31:57 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-16 21:31:57 +0800 |
| commit | 363fbc6e98f832471a17a10ec18e8823df6a2ed5 (patch) | |
| tree | 98f71ab1796c1a9c1df411eee5174dd92001ef94 /src/cli/io_error.rs | |
Initialize Rust project with billing calculation functionality
Diffstat (limited to 'src/cli/io_error.rs')
| -rw-r--r-- | src/cli/io_error.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/cli/io_error.rs b/src/cli/io_error.rs new file mode 100644 index 0000000..49b9939 --- /dev/null +++ b/src/cli/io_error.rs @@ -0,0 +1,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()) +} |
