Skip to content

Commit

Permalink
Merge pull request #42 from prettynatty/master
Browse files Browse the repository at this point in the history
implement Debug for Pool
  • Loading branch information
abonander committed Jan 10, 2020
2 parents 0a5aaca + e7026ce commit 5e9887a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sqlx-core/src/pool/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ where
&self.options
}

pub(super) fn url(&self) -> &str {
&self.url
}

pub(super) fn size(&self) -> u32 {
self.size.load(Ordering::Acquire)
}
Expand All @@ -78,6 +82,10 @@ where
self.pool_rx.len()
}

pub(super) fn closed(&self) -> bool {
self.closed.load(Ordering::SeqCst)
}

pub(super) async fn close(&self) {
self.closed.store(true, Ordering::Release);

Expand Down
13 changes: 13 additions & 0 deletions sqlx-core/src/pool/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! **Pool** for SQLx database connections.

use std::{
fmt,
ops::{Deref, DerefMut},
sync::Arc,
time::{Duration, Instant},
Expand Down Expand Up @@ -141,6 +142,18 @@ where
}
}

impl<DB: Database> fmt::Debug for Pool<DB> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Pool")
.field("url", &self.inner.url())
.field("size", &self.inner.size())
.field("num_idle", &self.inner.num_idle())
.field("closed", &self.inner.closed())
.field("options", self.inner.options())
.finish()
}
}

const DEREF_ERR: &str = "(bug) connection already released to pool";

impl<DB: Database> Deref for Connection<DB> {
Expand Down
1 change: 1 addition & 0 deletions sqlx-core/src/pool/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ where
}
}

#[derive(Debug)]
pub(crate) struct Options {
pub max_size: u32,
pub connect_timeout: Duration,
Expand Down

0 comments on commit 5e9887a

Please sign in to comment.