Skip to content

Commit ad1d7a8

Browse files
authored
Derive clone and debug for postgresql arguments (#3687)
1 parent a408c49 commit ad1d7a8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

sqlx-postgres/src/arguments.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use sqlx_core::error::BoxDynError;
2222
// that has a patch, we then apply the patch which should write to &mut Vec<u8>,
2323
// backtrack and update the prefixed-len, then write until the next patch offset
2424

25-
#[derive(Default)]
25+
#[derive(Default, Debug, Clone)]
2626
pub struct PgArgumentBuffer {
2727
buffer: Vec<u8>,
2828

@@ -46,20 +46,32 @@ pub struct PgArgumentBuffer {
4646
type_holes: Vec<(usize, HoleKind)>, // Vec<{ offset, type_name }>
4747
}
4848

49+
#[derive(Debug, Clone)]
4950
enum HoleKind {
5051
Type { name: UStr },
5152
Array(Arc<PgArrayOf>),
5253
}
5354

55+
#[derive(Clone)]
5456
struct Patch {
5557
buf_offset: usize,
5658
arg_index: usize,
5759
#[allow(clippy::type_complexity)]
58-
callback: Box<dyn Fn(&mut [u8], &PgTypeInfo) + 'static + Send + Sync>,
60+
callback: Arc<dyn Fn(&mut [u8], &PgTypeInfo) + 'static + Send + Sync>,
61+
}
62+
63+
impl fmt::Debug for Patch {
64+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65+
f.debug_struct("Patch")
66+
.field("buf_offset", &self.buf_offset)
67+
.field("arg_index", &self.arg_index)
68+
.field("callback", &"<callback>")
69+
.finish()
70+
}
5971
}
6072

6173
/// Implementation of [`Arguments`] for PostgreSQL.
62-
#[derive(Default)]
74+
#[derive(Default, Debug, Clone)]
6375
pub struct PgArguments {
6476
// Types of each bind parameter
6577
pub(crate) types: Vec<PgTypeInfo>,
@@ -194,7 +206,7 @@ impl PgArgumentBuffer {
194206
self.patches.push(Patch {
195207
buf_offset: offset,
196208
arg_index,
197-
callback: Box::new(callback),
209+
callback: Arc::new(callback),
198210
});
199211
}
200212

sqlx-postgres/src/type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub enum PgTypeKind {
185185
Range(PgTypeInfo),
186186
}
187187

188-
#[derive(Debug)]
188+
#[derive(Debug, Clone)]
189189
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
190190
pub struct PgArrayOf {
191191
pub(crate) elem_name: UStr,

0 commit comments

Comments
 (0)