# CancellationToken

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-system/threading/struct-cancellationtoken/

**struct** · [`ferroui-system`](/docs/0.5.0/api/ferroui-system/) · v0.5.0

```rust
struct CancellationToken
```

Propagates notification that operations should be canceled.

The clones of a token share its state: any of them cancels it, and all of them see it.
`Default` is `none`, a token that can never be canceled (the default of .NET's
`CancellationToken`; `tokio_util`'s default is a new token).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L135)

## Members

- [`new`](#function-new)
- [`none`](#function-none)
- [`can_be_cancelled`](#function-can_be_cancelled)
- [`can_be_canceled`](#function-can_be_canceled)
- [`is_cancelled`](#function-is_cancelled)
- [`is_cancellation_requested`](#function-is_cancellation_requested)
- [`cancel`](#function-cancel)
- [`child_token`](#function-child_token)
- [`cancelled`](#function-cancelled)
- [`drop_guard`](#function-drop_guard)
- [`register`](#function-register)
- [`register_guarded`](#function-register_guarded)
- [`register_handle`](#function-register_handle)
- [`register_local`](#function-register_local)
- [`register_local_guarded`](#function-register_local_guarded)
- [`register_local_handle`](#function-register_local_handle)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```

A token that can be canceled, by itself and its clones (a new `CancellationTokenSource`
and its token in one).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L142)

<a id="function-none"></a>

### none

```rust
const fn none() -> Self
```

A token that can never be canceled.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L147)

<a id="function-can_be_cancelled"></a>

### can_be_cancelled

```rust
fn can_be_cancelled(self: &Self) -> bool
```

Whether this token is capable of being in the canceled state.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L152)

<a id="function-can_be_canceled"></a>

### can_be_canceled

```rust
fn can_be_canceled(self: &Self) -> bool
```

Whether this token is capable of being in the canceled state.

> **Deprecated since 0.5.0.** use `can_be_cancelled`

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L158)

<a id="function-is_cancelled"></a>

### is_cancelled

```rust
fn is_cancelled(self: &Self) -> bool
```

Whether the token is canceled.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L163)

<a id="function-is_cancellation_requested"></a>

### is_cancellation_requested

```rust
fn is_cancellation_requested(self: &Self) -> bool
```

Whether the token is canceled.

> **Deprecated since 0.5.0.** use `is_cancelled`

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L169)

<a id="function-cancel"></a>

### cancel

```rust
fn cancel(self: &Self)
```

Cancels the token and its children, and runs the registered callbacks and wakes the
futures awaiting it, on the calling thread, in the order of registration. Subsequent calls,
and calls on a token that cannot be canceled, do nothing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L176)

<a id="function-child_token"></a>

### child_token

```rust
fn child_token(self: &Self) -> CancellationToken
```

A token canceled when this one is, which can also be canceled on its own without
canceling this one. It is canceled at once when this one already is; a child of a token
that cannot be canceled is a new token. The children of a token are canceled in its pass
of the callbacks, in the order they were made among them; a child whose clones are all
dropped is removed from its parent.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L187)

<a id="function-cancelled"></a>

### cancelled

```rust
fn cancelled(self: &Self) -> WaitForCancellation
```

A future that completes when the token is canceled; at once when it already is, never for
a token that cannot be canceled. It owns a clone of the token, is `Send`, and is woken on
the cancelling thread, in the pass of the callbacks.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L215)

<a id="function-drop_guard"></a>

### drop_guard

```rust
fn drop_guard(self: Self) -> DropGuard
```

A guard that cancels the token when it is dropped, unless it is
disarmed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L221)

<a id="function-register"></a>

### register

```rust
fn register(self: &Self, callback: impl FnOnce() -> () + Send + 'static) -> CancellationGuard
```

Registers a callback that runs, on the cancelling thread, when the token is canceled; at
once on the calling thread when it already is. Dropping the guard removes it
(`CancellationGuard::detach` keeps it). The callback never runs for a token that cannot
be canceled.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L229)

<a id="function-register_guarded"></a>

### register_guarded

```rust
fn register_guarded(self: &Self, callback: impl FnOnce() -> () + Send + 'static) -> CancellationGuard
```

The former name of `register`.

> **Deprecated since 0.5.0.** use `register`, which gives the same guard

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L239)

<a id="function-register_handle"></a>

### register_handle

```rust
fn register_handle(self: &Self, callback: impl FnOnce() -> () + Send + 'static) -> CancellationTokenRegistration
```

Registers a callback that runs when the token is canceled. When the token is already
canceled the callback runs immediately.

Dropping the returned registration keeps the callback (the `IDisposable` contract).

> **Deprecated since 0.5.0.** use `register`, whose guard removes the callback when it is dropped; `detach()` keeps it

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L252)

<a id="function-register_local"></a>

### register_local

```rust
fn register_local(self: &Self, callback: impl FnOnce() -> () + 'static) -> CancellationGuard
```

Registers a callback that runs on the current thread when the token is canceled: at once
when it is canceled on this thread, or already canceled; through the schedule of this thread
(`crate::task::set_thread_schedule`; a dispatcher, in a job at its default priority), or
its queue of `run_pending`, when it is
canceled on another thread. The callback need not be `Send`; the guard is: dropped on
another thread, it removes the registration at once and the callback is dropped on its own
thread, the next time that thread runs its queue. `CancellationGuard::detach` keeps it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L269)

<a id="function-register_local_guarded"></a>

### register_local_guarded

```rust
fn register_local_guarded(self: &Self, callback: impl FnOnce() -> () + 'static) -> CancellationGuard
```

The former name of `register_local`.

> **Deprecated since 0.5.0.** use `register_local`, which gives the same guard

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L281)

<a id="function-register_local_handle"></a>

### register_local_handle

```rust
fn register_local_handle(self: &Self, callback: impl FnOnce() -> () + 'static) -> LocalCancellationTokenRegistration
```

Registers a callback that runs on the current thread when the token is canceled, as
`register_local` does; dropping the returned registration keeps it.

> **Deprecated since 0.5.0.** use `register_local`, whose guard removes the callback when it is dropped; `detach()` keeps it

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/threading/cancellation_token.rs#L292)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `Clone`
- `Default`
- `Debug`
- `From<CancellationTokenSource>`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
