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 policy<VALUE: Into<ThreadSchedulePolicy>>(self, value: VALUE) -> Self
pub fn policy<VALUE: Into<ThreadSchedulePolicy>>(self, value: VALUE) -> Self
The thread’s unix scheduling policy.
For more information, see
crate::unix::ThreadSchedulePolicy and crate::unix::set_thread_priority_and_policy.
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
sourcefn cmp(&self, other: &ThreadBuilder) -> Ordering
fn cmp(&self, other: &ThreadBuilder) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
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
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