Skip to content

Commit

Permalink
Derive clone and debug for postgresql arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
remysaissy committed Jan 16, 2025
1 parent f6d2fa3 commit ea52623
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions sqlx-postgres/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sqlx_core::error::BoxDynError;
// that has a patch, we then apply the patch which should write to &mut Vec<u8>,
// backtrack and update the prefixed-len, then write until the next patch offset

#[derive(Default)]
#[derive(Default, Debug, Clone)]
pub struct PgArgumentBuffer {
buffer: Vec<u8>,

Expand All @@ -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<PgArrayOf>),
}

#[derive(Clone)]
struct Patch {
buf_offset: usize,
arg_index: usize,
#[allow(clippy::type_complexity)]
callback: Box<dyn Fn(&mut [u8], &PgTypeInfo) + 'static + Send + Sync>,
callback: Arc<dyn Fn(&mut [u8], &PgTypeInfo) + 'static + Send + Sync>,
}

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", &"<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<PgTypeInfo>,
Expand Down Expand Up @@ -194,7 +206,7 @@ impl PgArgumentBuffer {
self.patches.push(Patch {
buf_offset: offset,
arg_index,
callback: Box::new(callback),
callback: Arc::new(callback),
});
}

Expand Down
2 changes: 1 addition & 1 deletion sqlx-postgres/src/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ea52623

Please sign in to comment.