Skip to content

Add missing trait implementations for ScopedJoinHandle #136912

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 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion library/std/src/os/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#[allow(deprecated)]
use crate::os::unix::raw::pthread_t;
use crate::sys_common::{AsInner, IntoInner};
use crate::thread::JoinHandle;
use crate::thread::{JoinHandle, ScopedJoinHandle};

#[stable(feature = "thread_extensions", since = "1.9.0")]
#[allow(deprecated)]
Expand Down Expand Up @@ -39,3 +39,14 @@ impl<T> JoinHandleExt for JoinHandle<T> {
self.into_inner().into_id() as RawPthread
}
}

#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
impl<T> JoinHandleExt for ScopedJoinHandle<'_, T> {
fn as_pthread_t(&self) -> RawPthread {
self.as_inner().id() as RawPthread
}

fn into_pthread_t(self) -> RawPthread {
self.into_inner().into_id() as RawPthread
}
}
16 changes: 16 additions & 0 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,19 @@ impl<T> From<crate::thread::JoinHandle<T>> for OwnedHandle {
join_handle.into_inner().into_handle().into_inner()
}
}

#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
impl<T> AsHandle for crate::thread::ScopedJoinHandle<'_, T> {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
}
}

#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
impl<T> From<crate::thread::ScopedJoinHandle<'_, T>> for OwnedHandle {
#[inline]
fn from(join_handle: crate::thread::ScopedJoinHandle<'_, T>) -> OwnedHandle {
join_handle.into_inner().into_handle().into_inner()
}
}
16 changes: 16 additions & 0 deletions library/std/src/os/windows/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ impl<T> IntoRawHandle for thread::JoinHandle<T> {
self.into_inner().into_handle().into_raw_handle() as *mut _
}
}

#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
impl<T> AsRawHandle for thread::ScopedJoinHandle<'_, T> {
#[inline]
fn as_raw_handle(&self) -> RawHandle {
self.as_inner().handle().as_raw_handle() as *mut _
}
}

#[stable(feature = "scoped_thread_extensions", since = "CURRENT_RUSTC_VERSION")]
impl<T> IntoRawHandle for thread::ScopedJoinHandle<'_, T> {
#[inline]
fn into_raw_handle(self) -> RawHandle {
self.into_inner().into_handle().into_raw_handle() as *mut _
}
}
15 changes: 14 additions & 1 deletion library/std/src/thread/scoped.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::{Builder, JoinInner, Result, Thread, current_or_unnamed};
use super::{Builder, JoinInner, Result, Thread, current_or_unnamed, imp};
use crate::marker::PhantomData;
use crate::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
use crate::sync::Arc;
use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use crate::sys_common::{AsInner, IntoInner};
use crate::{fmt, io};

/// A scope to spawn scoped threads in.
Expand Down Expand Up @@ -347,3 +348,15 @@ impl<'scope, T> fmt::Debug for ScopedJoinHandle<'scope, T> {
f.debug_struct("ScopedJoinHandle").finish_non_exhaustive()
}
}

impl<T> AsInner<imp::Thread> for ScopedJoinHandle<'_, T> {
fn as_inner(&self) -> &imp::Thread {
&self.0.native
}
}

impl<T> IntoInner<imp::Thread> for ScopedJoinHandle<'_, T> {
fn into_inner(self) -> imp::Thread {
self.0.native
}
}
Loading