Skip to content

Commit 4efc16b

Browse files
committed
breaking(pool): use usize for all connection counts
1 parent 028084b commit 4efc16b

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

sqlx-core/src/pool/inner.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::sync::{AsyncSemaphore, AsyncSemaphoreReleaser};
1010

1111
use std::cmp;
1212
use std::future::Future;
13-
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
13+
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
1414
use std::sync::{Arc, RwLock};
1515
use std::task::Poll;
1616

@@ -26,7 +26,7 @@ pub(crate) struct PoolInner<DB: Database> {
2626
pub(super) connect_options: RwLock<Arc<<DB::Connection as Connection>::Options>>,
2727
pub(super) idle_conns: ArrayQueue<Idle<DB>>,
2828
pub(super) semaphore: AsyncSemaphore,
29-
pub(super) size: AtomicU32,
29+
pub(super) size: AtomicUsize,
3030
pub(super) num_idle: AtomicUsize,
3131
is_closed: AtomicBool,
3232
pub(super) on_closed: event_listener::Event,
@@ -55,7 +55,7 @@ impl<DB: Database> PoolInner<DB> {
5555
connect_options: RwLock::new(Arc::new(connect_options)),
5656
idle_conns: ArrayQueue::new(capacity),
5757
semaphore: AsyncSemaphore::new(options.fair, semaphore_capacity),
58-
size: AtomicU32::new(0),
58+
size: AtomicUsize::new(0),
5959
num_idle: AtomicUsize::new(0),
6060
is_closed: AtomicBool::new(false),
6161
on_closed: event_listener::Event::new(),
@@ -71,7 +71,7 @@ impl<DB: Database> PoolInner<DB> {
7171
pool
7272
}
7373

74-
pub(super) fn size(&self) -> u32 {
74+
pub(super) fn size(&self) -> usize {
7575
self.size.load(Ordering::Acquire)
7676
}
7777

@@ -108,7 +108,8 @@ impl<DB: Database> PoolInner<DB> {
108108
}
109109

110110
// Wait for all permits to be released.
111-
let _permits = self.semaphore.acquire(permits).await;
111+
#[allow(clippy::cast_possible_truncation)]
112+
let _permits = self.semaphore.acquire(permits as u32).await;
112113
}
113114
}
114115
}

sqlx-core/src/pool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl<DB: Database> Pool<DB> {
496496
}
497497

498498
/// Returns the number of connections currently active. This includes idle connections.
499-
pub fn size(&self) -> u32 {
499+
pub fn size(&self) -> usize {
500500
self.0.size()
501501
}
502502

sqlx-core/src/pool/options.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ pub struct PoolOptions<DB: Database> {
7474
+ Sync,
7575
>,
7676
>,
77-
pub(crate) max_connections: u32,
77+
pub(crate) max_connections: usize,
7878
pub(crate) acquire_time_level: LevelFilter,
7979
pub(crate) acquire_slow_level: LevelFilter,
8080
pub(crate) acquire_slow_threshold: Duration,
8181
pub(crate) acquire_timeout: Duration,
82-
pub(crate) min_connections: u32,
82+
pub(crate) min_connections: usize,
8383
pub(crate) max_lifetime: Option<Duration>,
8484
pub(crate) idle_timeout: Option<Duration>,
8585
pub(crate) fair: bool,
@@ -170,13 +170,13 @@ impl<DB: Database> PoolOptions<DB> {
170170
/// Be mindful of the connection limits for your database as well as other applications
171171
/// which may want to connect to the same database (or even multiple instances of the same
172172
/// application in high-availability deployments).
173-
pub fn max_connections(mut self, max: u32) -> Self {
173+
pub fn max_connections(mut self, max: usize) -> Self {
174174
self.max_connections = max;
175175
self
176176
}
177177

178178
/// Get the maximum number of connections that this pool should maintain
179-
pub fn get_max_connections(&self) -> u32 {
179+
pub fn get_max_connections(&self) -> usize {
180180
self.max_connections
181181
}
182182

@@ -202,13 +202,13 @@ impl<DB: Database> PoolOptions<DB> {
202202
/// [`max_lifetime`]: Self::max_lifetime
203203
/// [`idle_timeout`]: Self::idle_timeout
204204
/// [`max_connections`]: Self::max_connections
205-
pub fn min_connections(mut self, min: u32) -> Self {
205+
pub fn min_connections(mut self, min: usize) -> Self {
206206
self.min_connections = min;
207207
self
208208
}
209209

210210
/// Get the minimum number of connections to maintain at all times.
211-
pub fn get_min_connections(&self) -> u32 {
211+
pub fn get_min_connections(&self) -> usize {
212212
self.min_connections
213213
}
214214

0 commit comments

Comments
 (0)