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
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for ThreadBuilder
impl Debug for ThreadBuilder
sourceimpl Default for ThreadBuilder
impl Default for ThreadBuilder
sourcefn default() -> ThreadBuilder
fn default() -> ThreadBuilder
Returns the “default value” for a type. Read more
sourceimpl Hash for ThreadBuilder
impl Hash for ThreadBuilder
sourceimpl Ord for ThreadBuilder
impl Ord for ThreadBuilder
sourceimpl PartialEq<ThreadBuilder> for ThreadBuilder
impl PartialEq<ThreadBuilder> for ThreadBuilder
sourcefn eq(&self, other: &ThreadBuilder) -> bool
fn eq(&self, other: &ThreadBuilder) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &ThreadBuilder) -> bool
fn ne(&self, other: &ThreadBuilder) -> bool
This method tests for !=.
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>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Eq for ThreadBuilder
impl StructuralEq for ThreadBuilder
impl StructuralPartialEq for ThreadBuilder
Auto Trait Implementations
impl RefUnwindSafe for ThreadBuilder
impl Send for ThreadBuilder
impl Sync for ThreadBuilder
impl Unpin for ThreadBuilder
impl UnwindSafe for ThreadBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more