Struct ThreadBuilder
pub struct ThreadBuilder { /* private fields */ }Expand description
A copy of the std::thread::Builder builder allowing to set priority settings.
use thread_priority::*;
let thread = ThreadBuilder::default()
.name("MyThread")
.priority(ThreadPriority::Max)
.spawn(|result| {
// This is printed out from within the spawned thread.
println!("Set priority result: {:?}", result);
assert!(result.is_ok());
}).unwrap();
thread.join();
// Another example where we don't care about the priority having been set.
let thread = ThreadBuilder::default()
.name("MyThread")
.priority(ThreadPriority::Max)
.spawn_careless(|| {
// This is printed out from within the spawned thread.
println!("We don't care about the priority result.");
}).unwrap();
thread.join();If the compiler version is at least 1.63, the scoped thread support is also enabled.
use thread_priority::*;
// Scoped thread is also supported if the compiler version is at least 1.63.
let mut x = 0;
std::thread::scope(|s|{
let thread = ThreadBuilder::default()
.name("MyThread")
.priority(ThreadPriority::Max)
.spawn_scoped(s, |result| {
// This is printed out from within the spawned thread.
println!("Set priority result: {:?}", result);
assert!(result.is_ok());
x += 1;
}).unwrap();
thread.join();
});
assert_eq!(x, 1);
// Scoped thread also has a "careless" mode.
std::thread::scope(|s|{
let thread = ThreadBuilder::default()
.name("MyThread")
.priority(ThreadPriority::Max)
.spawn_scoped_careless(s, || {
// This is printed out from within the spawned thread.
println!("We don't care about the priority result.");
x += 1;
}).unwrap();
thread.join();
});
assert_eq!(x, 2);Implementations§
§impl ThreadBuilder
impl ThreadBuilder
pub fn name<VALUE>(self, value: VALUE) -> ThreadBuilder
pub fn name<VALUE>(self, value: VALUE) -> ThreadBuilder
Names the thread-to-be. Currently the name is used for identification only in panic messages.
The name must not contain null bytes (\0).
For more information about named threads, see
std::thread::Builder::name().
pub fn stack_size<VALUE>(self, value: VALUE) -> ThreadBuilder
pub fn stack_size<VALUE>(self, value: VALUE) -> ThreadBuilder
Sets the size of the stack (in bytes) for the new thread.
The actual stack size may be greater than this value if the platform specifies a minimal stack size.
For more information about the stack size for threads, see
std::thread::Builder::stack_size().
pub fn priority<VALUE>(self, value: VALUE) -> ThreadBuilderwhere
VALUE: Into<ThreadPriority>,
pub fn priority<VALUE>(self, value: VALUE) -> ThreadBuilderwhere
VALUE: Into<ThreadPriority>,
The thread’s custom priority.
For more information about the stack size for threads, see
ThreadPriority.
pub fn policy<VALUE>(self, value: VALUE) -> ThreadBuilderwhere
VALUE: Into<ThreadSchedulePolicy>,
Available on Unix only.
pub fn policy<VALUE>(self, value: VALUE) -> ThreadBuilderwhere
VALUE: Into<ThreadSchedulePolicy>,
The thread’s unix scheduling policy.
For more information, see
crate::unix::ThreadSchedulePolicy and crate::unix::set_thread_priority_and_policy.
pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>, Error>
pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>, Error>
Spawns a new thread by taking ownership of the Builder, and returns an
std::io::Result to its std::thread::JoinHandle.
pub fn spawn_scoped<'scope, 'env, F, T>(
self,
scope: &'scope Scope<'scope, 'env>,
f: F,
) -> Result<ScopedJoinHandle<'scope, T>, Error>
pub fn spawn_scoped<'scope, 'env, F, T>( self, scope: &'scope Scope<'scope, 'env>, f: F, ) -> Result<ScopedJoinHandle<'scope, T>, Error>
Spawns a new scoped thread by taking ownership of the Builder, and returns an
std::io::Result to its std::thread::ScopedJoinHandle.
pub fn spawn_careless<F, T>(self, f: F) -> Result<JoinHandle<T>, Error>
pub fn spawn_careless<F, T>(self, f: F) -> Result<JoinHandle<T>, Error>
Spawns a new thread by taking ownership of the Builder, and returns an
std::io::Result to its std::thread::JoinHandle.
pub fn spawn_scoped_careless<'scope, 'env, F, T>(
self,
scope: &'scope Scope<'scope, 'env>,
f: F,
) -> Result<ScopedJoinHandle<'scope, T>, Error>
pub fn spawn_scoped_careless<'scope, 'env, F, T>( self, scope: &'scope Scope<'scope, 'env>, f: F, ) -> Result<ScopedJoinHandle<'scope, T>, Error>
Spawns a new scoped thread by taking ownership of the Builder, and returns an
std::io::Result to its std::thread::ScopedJoinHandle.
Trait Implementations§
§impl Clone for ThreadBuilder
impl Clone for ThreadBuilder
§fn clone(&self) -> ThreadBuilder
fn clone(&self) -> ThreadBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for ThreadBuilder
impl Debug for ThreadBuilder
§impl Default for ThreadBuilder
impl Default for ThreadBuilder
§fn default() -> ThreadBuilder
fn default() -> ThreadBuilder
§impl Hash for ThreadBuilder
impl Hash for ThreadBuilder
§impl Ord for ThreadBuilder
impl Ord for ThreadBuilder
§impl PartialEq for ThreadBuilder
impl PartialEq for ThreadBuilder
§impl PartialOrd for ThreadBuilder
impl PartialOrd for ThreadBuilder
impl Eq for ThreadBuilder
impl StructuralPartialEq for ThreadBuilder
Auto Trait Implementations§
impl Freeze for ThreadBuilder
impl RefUnwindSafe for ThreadBuilder
impl Send for ThreadBuilder
impl Sync for ThreadBuilder
impl Unpin for ThreadBuilder
impl UnsafeUnpin for ThreadBuilder
impl UnwindSafe for ThreadBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 104 bytes