]>
git.proxmox.com Git - rustc.git/blob - vendor/futures-executor/src/enter.rs
4 thread_local
!(static ENTERED
: Cell
<bool
> = Cell
::new(false));
6 /// Represents an executor context.
8 /// For more details, see [`enter` documentation](enter()).
13 /// An error returned by `enter` if an execution scope has already been
15 pub struct EnterError
{
19 impl fmt
::Debug
for EnterError
{
20 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
21 f
.debug_struct("EnterError").finish()
25 impl fmt
::Display
for EnterError
{
26 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
27 write
!(f
, "an execution scope has already been entered")
31 impl std
::error
::Error
for EnterError {}
33 /// Marks the current thread as being within the dynamic extent of an
36 /// Executor implementations should call this function before beginning to
37 /// execute a tasks, and drop the returned [`Enter`](Enter) value after
38 /// completing task execution:
41 /// use futures::executor::enter;
43 /// let enter = enter().expect("...");
48 /// Doing so ensures that executors aren't
49 /// accidentally invoked in a nested fashion.
53 /// Returns an error if the current thread is already marked, in which case the
54 /// caller should panic with a tailored error message.
55 pub fn enter() -> Result
<Enter
, EnterError
> {
58 Err(EnterError { _priv: () }
)
62 Ok(Enter { _priv: () }
)
67 impl fmt
::Debug
for Enter
{
68 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
69 f
.debug_struct("Enter").finish()