Skip to content
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

sync: use usize instead of u32 for SemaphorePermit::split #6478

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions tokio/src/sync/semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,12 @@ impl<'a> SemaphorePermit<'a> {
/// Splits `n` permits from `self` and returns a new [`SemaphorePermit`] instance that holds `n` permits.
///
/// If there are insufficient permits and it's not possible to reduce by `n`, returns `None`.
pub fn split(&mut self, n: u32) -> Option<Self> {
pub fn split(&mut self, n: usize) -> Option<Self> {
let n = match u32::try_from(n) {
Ok(n) => n,
Err(_) => return None,
};
Darksonn marked this conversation as resolved.
Show resolved Hide resolved

if n > self.permits {
return None;
}
Expand All @@ -1008,8 +1013,8 @@ impl<'a> SemaphorePermit<'a> {
}

/// Returns the number of permits held by `self`.
pub fn num_permits(&self) -> u32 {
self.permits
pub fn num_permits(&self) -> usize {
self.permits as usize
}
}

Expand Down Expand Up @@ -1047,7 +1052,12 @@ impl OwnedSemaphorePermit {
/// # Note
///
/// It will clone the owned `Arc<Semaphore>` to construct the new instance.
pub fn split(&mut self, n: u32) -> Option<Self> {
pub fn split(&mut self, n: usize) -> Option<Self> {
let n = match u32::try_from(n) {
Ok(n) => n,
Err(_) => return None,
};
Darksonn marked this conversation as resolved.
Show resolved Hide resolved

if n > self.permits {
return None;
}
Expand All @@ -1066,8 +1076,8 @@ impl OwnedSemaphorePermit {
}

/// Returns the number of permits held by `self`.
pub fn num_permits(&self) -> u32 {
self.permits
pub fn num_permits(&self) -> usize {
self.permits as usize
}
}

Expand Down
Loading