From ea52623bbdf92a38bf7e18aa22b17f824f7a5507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20SAISSY?= Date: Thu, 16 Jan 2025 13:56:53 +0100 Subject: [PATCH] Derive clone and debug for postgresql arguments --- sqlx-postgres/src/arguments.rs | 20 ++++++++++++++++---- sqlx-postgres/src/type_info.rs | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sqlx-postgres/src/arguments.rs b/sqlx-postgres/src/arguments.rs index bc7e861c52..62a227e52d 100644 --- a/sqlx-postgres/src/arguments.rs +++ b/sqlx-postgres/src/arguments.rs @@ -22,7 +22,7 @@ use sqlx_core::error::BoxDynError; // that has a patch, we then apply the patch which should write to &mut Vec, // backtrack and update the prefixed-len, then write until the next patch offset -#[derive(Default)] +#[derive(Default, Debug, Clone)] pub struct PgArgumentBuffer { buffer: Vec, @@ -46,20 +46,32 @@ pub struct PgArgumentBuffer { type_holes: Vec<(usize, HoleKind)>, // Vec<{ offset, type_name }> } +#[derive(Debug, Clone)] enum HoleKind { Type { name: UStr }, Array(Arc), } +#[derive(Clone)] struct Patch { buf_offset: usize, arg_index: usize, #[allow(clippy::type_complexity)] - callback: Box, + callback: Arc, +} + +impl fmt::Debug for Patch { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Patch") + .field("buf_offset", &self.buf_offset) + .field("arg_index", &self.arg_index) + .field("callback", &"") + .finish() + } } /// Implementation of [`Arguments`] for PostgreSQL. -#[derive(Default)] +#[derive(Default, Debug, Clone)] pub struct PgArguments { // Types of each bind parameter pub(crate) types: Vec, @@ -194,7 +206,7 @@ impl PgArgumentBuffer { self.patches.push(Patch { buf_offset: offset, arg_index, - callback: Box::new(callback), + callback: Arc::new(callback), }); } diff --git a/sqlx-postgres/src/type_info.rs b/sqlx-postgres/src/type_info.rs index 3d948f73d4..28c56758e9 100644 --- a/sqlx-postgres/src/type_info.rs +++ b/sqlx-postgres/src/type_info.rs @@ -185,7 +185,7 @@ pub enum PgTypeKind { Range(PgTypeInfo), } -#[derive(Debug)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))] pub struct PgArrayOf { pub(crate) elem_name: UStr,