From 363fbc6e98f832471a17a10ec18e8823df6a2ed5 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 16 Apr 2026 21:31:57 +0800 Subject: Initialize Rust project with billing calculation functionality --- src/cli/io_error.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/cli/io_error.rs (limited to 'src/cli/io_error.rs') 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 for IOError { + fn from(error: std::io::Error) -> Self { + Self::new(error) + } +} + +impl Serialize for IOError { + fn serialize(&self, serializer: S) -> Result + 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()) +} -- cgit