diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 78fec8d2..16f60416 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -112,32 +112,22 @@ impl From for WindowsResult { } } -impl From for WindowsResult { - fn from(return_value: isize) -> Self { - match return_value { - 0 => Self::Err(std::io::Error::last_os_error().into()), - _ => Self::Ok(return_value), - } - } +macro_rules! impl_from_integer_for_windows_result { + ( $( $integer_type:ty ),+ ) => { + $( + impl From<$integer_type> for WindowsResult<$integer_type, Error> { + fn from(return_value: $integer_type) -> Self { + match return_value { + 0 => Self::Err(std::io::Error::last_os_error().into()), + _ => Self::Ok(return_value), + } + } + } + )+ + }; } -impl From for WindowsResult { - fn from(return_value: u32) -> Self { - match return_value { - 0 => Self::Err(std::io::Error::last_os_error().into()), - _ => Self::Ok(return_value), - } - } -} - -impl From for WindowsResult { - fn from(return_value: i32) -> Self { - match return_value { - 0 => Self::Err(std::io::Error::last_os_error().into()), - _ => Self::Ok(return_value), - } - } -} +impl_from_integer_for_windows_result!(isize, u32, i32); impl From> for Result { fn from(result: WindowsResult) -> Self {