Skip to content

Change how checkout IDs are configured for debug only. #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/client/pool/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ use crate::client::conn::connector::{Connector, ConnectorMeta};
use crate::client::conn::Protocol;
use crate::client::conn::Transport;

#[cfg(debug_assertions)]
use self::ids::CheckoutId;
use super::key::Token;
use super::Config;
use super::PoolRef;
use super::PoolableConnection;
use super::Pooled;

#[cfg(debug_assertions)]
static CHECKOUT_ID: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(1);
mod ids {
use core::fmt;

#[cfg(debug_assertions)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct CheckoutId(usize);
static CHECKOUT_ID: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(1);

#[cfg(debug_assertions)]
impl CheckoutId {
fn new() -> Self {
CheckoutId(CHECKOUT_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst))
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) struct CheckoutId(pub(super) usize);

impl CheckoutId {
pub(super) fn new() -> Self {
CheckoutId(CHECKOUT_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst))
}
}
}

#[cfg(debug_assertions)]
impl fmt::Display for CheckoutId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "checkout-{}", self.0)
impl fmt::Display for CheckoutId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "checkout-{}", self.0)
}
}
}

Expand Down
Loading