From 1349c8a0eb347b1fee84eba301a1ad0b1a357aa7 Mon Sep 17 00:00:00 2001 From: Vasilito Date: Thu, 7 May 2026 21:17:24 +0100 Subject: [PATCH] style: format Cub library modules Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../system/cub/source/cub-lib/src/aur.rs | 55 ++++++++++++++++++- .../system/cub/source/cub-lib/src/lib.rs | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/local/recipes/system/cub/source/cub-lib/src/aur.rs b/local/recipes/system/cub/source/cub-lib/src/aur.rs index 885d25806..92f8cadad 100644 --- a/local/recipes/system/cub/source/cub-lib/src/aur.rs +++ b/local/recipes/system/cub/source/cub-lib/src/aur.rs @@ -41,10 +41,53 @@ pub struct AurPackage { #[serde(rename = "LastModified")] pub last_modified: i64, #[serde(rename = "OutOfDate")] - #[serde(default)] + #[serde(default, deserialize_with = "deserialize_out_of_date")] pub out_of_date: Option, } +fn deserialize_out_of_date<'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + use serde::de; + + struct OutOfDateVisitor; + + impl<'de> de::Visitor<'de> for OutOfDateVisitor { + type Value = Option; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("null, boolean, or integer") + } + + fn visit_none(self) -> Result { + Ok(None) + } + + fn visit_unit(self) -> Result { + Ok(None) + } + + fn visit_bool(self, v: bool) -> Result { + Ok(Some(v)) + } + + fn visit_i64(self, v: i64) -> Result { + Ok(Some(v != 0)) + } + + fn visit_u64(self, v: u64) -> Result { + Ok(Some(v != 0)) + } + + fn visit_f64(self, v: f64) -> Result { + Ok(Some(v != 0.0)) + } + } + + deserializer.deserialize_any(OutOfDateVisitor) +} + #[derive(Debug, Deserialize)] struct AurRpcResponse { version: i64, @@ -200,7 +243,10 @@ fn parse_rpc_response(body: &str, empty_message: &str) -> Result .map_err(|err| aur_error(format!("failed to parse JSON response: {err}")))?; if rpc.version != 5 { - return Err(aur_error(format!("unexpected RPC version: {}", rpc.version))); + return Err(aur_error(format!( + "unexpected RPC version: {}", + rpc.version + ))); } if rpc.response_type == "error" { @@ -208,7 +254,10 @@ fn parse_rpc_response(body: &str, empty_message: &str) -> Result return Err(aur_error(message)); } - if rpc.response_type != "search" && rpc.response_type != "multiinfo" && rpc.response_type != "info" { + if rpc.response_type != "search" + && rpc.response_type != "multiinfo" + && rpc.response_type != "info" + { return Err(aur_error(format!( "unexpected RPC response type: {}", rpc.response_type diff --git a/local/recipes/system/cub/source/cub-lib/src/lib.rs b/local/recipes/system/cub/source/cub-lib/src/lib.rs index f2bbfab48..5c63aeb05 100644 --- a/local/recipes/system/cub/source/cub-lib/src/lib.rs +++ b/local/recipes/system/cub/source/cub-lib/src/lib.rs @@ -8,8 +8,8 @@ pub mod error; pub mod package; pub mod pkgbuild; pub mod rbpkgbuild; -pub mod recipe; pub mod rbsrcinfo; +pub mod recipe; pub mod sandbox; pub mod storage;