Struct re_viewer::external::crossbeam::thread::ScopedThreadBuilder
pub struct ScopedThreadBuilder<'scope, 'env> {
scope: &'scope Scope<'env>,
builder: Builder,
}
Expand description
Configures the properties of a new thread.
The two configurable properties are:
name
: Specifies an associated name for the thread.stack_size
: Specifies the desired stack size for the thread.
The spawn
method will take ownership of the builder and return an io::Result
of the
thread handle with the given configuration.
The Scope::spawn
method uses a builder with default configuration and unwraps its return
value. You may want to use this builder when you want to recover from a failure to launch a
thread.
§Examples
use crossbeam_utils::thread;
thread::scope(|s| {
s.builder()
.spawn(|_| println!("Running a child thread"))
.unwrap();
}).unwrap();
Fields§
§scope: &'scope Scope<'env>
§builder: Builder
Implementations§
§impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env>
impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env>
pub fn name(self, name: String) -> ScopedThreadBuilder<'scope, 'env>
pub fn name(self, name: String) -> ScopedThreadBuilder<'scope, 'env>
Sets the name for the new thread.
The name must not contain null bytes (\0
).
For more information about named threads, see here.
§Examples
use crossbeam_utils::thread;
use std::thread::current;
thread::scope(|s| {
s.builder()
.name("my thread".to_string())
.spawn(|_| assert_eq!(current().name(), Some("my thread")))
.unwrap();
}).unwrap();
pub fn stack_size(self, size: usize) -> ScopedThreadBuilder<'scope, 'env>
pub fn stack_size(self, size: usize) -> ScopedThreadBuilder<'scope, 'env>
Sets the size of the stack for the new thread.
The stack size is measured in bytes.
For more information about the stack size for threads, see here.
§Examples
use crossbeam_utils::thread;
thread::scope(|s| {
s.builder()
.stack_size(32 * 1024)
.spawn(|_| println!("Running a child thread"))
.unwrap();
}).unwrap();
pub fn spawn<F, T>(self, f: F) -> Result<ScopedJoinHandle<'scope, T>, Error>
pub fn spawn<F, T>(self, f: F) -> Result<ScopedJoinHandle<'scope, T>, Error>
Spawns a scoped thread with this configuration.
The scoped thread is passed a reference to this scope as an argument, which can be used for spawning nested threads.
The returned handle can be used to manually join the thread before the scope exits.
§Errors
Unlike the Scope::spawn
method, this method yields an
io::Result
to capture any failure to create the thread at
the OS level.
§Panics
Panics if a thread name was set and it contained null bytes.
§Examples
use crossbeam_utils::thread;
thread::scope(|s| {
let handle = s.builder()
.spawn(|_| {
println!("A child thread is running");
42
})
.unwrap();
// Join the thread and retrieve its result.
let res = handle.join().unwrap();
assert_eq!(res, 42);
}).unwrap();
Trait Implementations§
Auto Trait Implementations§
impl<'scope, 'env> Freeze for ScopedThreadBuilder<'scope, 'env>
impl<'scope, 'env> RefUnwindSafe for ScopedThreadBuilder<'scope, 'env>
impl<'scope, 'env> Send for ScopedThreadBuilder<'scope, 'env>
impl<'scope, 'env> Sync for ScopedThreadBuilder<'scope, 'env>
impl<'scope, 'env> Unpin for ScopedThreadBuilder<'scope, 'env>
impl<'scope, 'env> UnwindSafe for ScopedThreadBuilder<'scope, 'env>
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> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§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> 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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request