Struct thread_priority::ThreadBuilder
source · [−]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();Implementations
sourceimpl ThreadBuilder
impl ThreadBuilder
sourcepub fn name<VALUE: Into<String>>(self, value: VALUE) -> Self
pub fn name<VALUE: Into<String>>(self, value: VALUE) -> Self
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().
sourcepub fn stack_size<VALUE: Into<usize>>(self, value: VALUE) -> Self
pub fn stack_size<VALUE: Into<usize>>(self, value: VALUE) -> Self
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().
sourcepub fn priority<VALUE: Into<ThreadPriority>>(self, value: VALUE) -> Self
pub fn priority<VALUE: Into<ThreadPriority>>(self, value: VALUE) -> Self
The thread’s custom priority.
For more information about the stack size for threads, see
ThreadPriority.
sourcepub fn winapi_priority<VALUE: Into<WinAPIThreadPriority>>(
self,
value: VALUE
) -> Self
pub fn winapi_priority<VALUE: Into<WinAPIThreadPriority>>(
self,
value: VALUE
) -> Self
The WinAPI priority representation.
For more information, see
crate::windows::WinAPIThreadPriority.
sourcepub fn boost_enabled(self, value: bool) -> Self
pub fn boost_enabled(self, value: bool) -> Self
Disables or enables the ability of the system to temporarily boost the priority of a thread.
For more information, see
crate::windows::set_thread_priority_boost.
sourcepub fn ideal_processor<VALUE: Into<IdealProcessor>>(self, value: VALUE) -> Self
pub fn ideal_processor<VALUE: Into<IdealProcessor>>(self, value: VALUE) -> Self
Sets a preferred processor for a thread. The system schedules threads on their preferred processors whenever possible.
For more information, see
crate::windows::set_thread_ideal_processor.
sourcepub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>where
F: FnOnce(Result<(), Error>) -> T,
F: Send + 'static,
T: Send + 'static,
pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>where
F: FnOnce(Result<(), Error>) -> T,
F: Send + 'static,
T: Send + 'static,
Spawns a new thread by taking ownership of the Builder, and returns an
std::io::Result to its std::thread::JoinHandle.
sourcepub fn spawn_careless<F, T>(self, f: F) -> Result<JoinHandle<T>>where
F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static,
pub fn spawn_careless<F, T>(self, f: F) -> Result<JoinHandle<T>>where
F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static,
Spawns a new thread by taking ownership of the Builder, and returns an
std::io::Result to its std::thread::JoinHandle.
Trait Implementations
sourceimpl Clone for ThreadBuilder
impl Clone for ThreadBuilder
sourcefn clone(&self) -> ThreadBuilder
fn clone(&self) -> ThreadBuilder
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moresourceimpl Debug for ThreadBuilder
impl Debug for ThreadBuilder
sourceimpl Default for ThreadBuilder
impl Default for ThreadBuilder
sourcefn default() -> ThreadBuilder
fn default() -> ThreadBuilder
sourceimpl Hash for ThreadBuilder
impl Hash for ThreadBuilder
sourceimpl Ord for ThreadBuilder
impl Ord for ThreadBuilder
sourcefn cmp(&self, other: &ThreadBuilder) -> Ordering
fn cmp(&self, other: &ThreadBuilder) -> Ordering
1.21.0 · sourceconst fn max(self, other: Self) -> Selfwhere
Self: Sized,
const fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourceconst fn min(self, other: Self) -> Selfwhere
Self: Sized,
const fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialEq<ThreadBuilder> for ThreadBuilder
impl PartialEq<ThreadBuilder> for ThreadBuilder
sourcefn eq(&self, other: &ThreadBuilder) -> bool
fn eq(&self, other: &ThreadBuilder) -> bool
sourceimpl PartialOrd<ThreadBuilder> for ThreadBuilder
impl PartialOrd<ThreadBuilder> for ThreadBuilder
sourcefn partial_cmp(&self, other: &ThreadBuilder) -> Option<Ordering>
fn partial_cmp(&self, other: &ThreadBuilder) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more