We use Box to be able to catch memory leaks using miri/valgrind.
```
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
99 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: `-D dead-code` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(dead_code)]`
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
99 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
100 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
118 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
118 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
119 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
137 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
137 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
138 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
156 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
156 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
157 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
185 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
185 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
186 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
216 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
216 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
217 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
247 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
247 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
248 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
285 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
285 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
286 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
error: field `0` is never read
--> tests/join.rs:29:24
|
29 | struct Fut(Box<i32>);
| --- ^^^^^^^^
| |
| field in this struct
...
319 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
29 | struct Fut(());
| ~~
error: field `0` is never read
--> tests/join.rs:47:24
|
47 | struct Out(Box<i32>, bool);
| --- ^^^^^^^^
| |
| field in this struct
...
319 | future!(f, POLL, DROP_F, DROP_T);
| -------------------------------- in this macro invocation
|
= note: this error originates in the macro `future` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
47 | struct Out((), bool);
| ~~
error: field `0` is never read
--> tests/join.rs:75:26
|
75 | struct Guard(Box<i32>);
| ----- ^^^^^^^^
| |
| field in this struct
...
320 | schedule!(s, SCHEDULE, DROP_S);
| ------------------------------ in this macro invocation
|
= note: this error originates in the macro `schedule` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
75 | struct Guard(());
| ~~
```
These APIs were removed prior to async-task 4.0 (in commit deb709f419); they can however be useful to e.g. pass Runnable as a context argument to GCD's dispatch_async_f, which takes an opaque *mut () as an argument. Without exposing from_raw/into_raw one has to box the Runnable in order to get something that can be passed across that boundary, which seems wasteful.
This PR makes RawTask::TASK_LAYOUT non-optional by panicking in const context in case of not having it. Note that due to MSRV being 1.47 a panic! could not be used in const context, so I resorted to out of bounds array read.
The error message in case of failure is that of the faulty expression ('async_task_failed_to_compile[1]'), which is pretty bad, but in reality we should not be getting there ever.
* docs(examples): Add example for capturing metadata
Adds an example of capturing metadata within the future creation
function.
* refactor(examples): Added ByDuration::duration helper
* style(examples): Deref the &mut &Cell to &Cell immediately
One less deref involved after this.
* style(examples): Fix clippy
- Ensure that the allocation doesn't exceed `isize::MAX` (#32)
- Add `FallibleTask::is_finished()` (#34)
- Add a metadata generic parameter to tasks (#33)
- Add panic propagation to tasks (#37)
- Add a way to tell if the task was woken while running from the schedule function (#42)
* Add metadata to tasks
* Make sure to drop the header.
* Revamp so that it uses a generator instead
* Fix heap allocation
* Slightly more elegant strategy
* Add a test for using metadata.
* Use non-driven block_on() instead.
```
warning: use of constant `std::isize::MAX` that will be deprecated in a future Rust version: replaced by the `MAX` associated constant on this type
--> src/utils.rs💯68
|
100 | if !new_align.is_power_of_two() || new_size > core::isize::MAX as usize - (new_align - 1) {
| ^^^
|
= note: requested on the command line with `-W deprecated-in-future`
warning: use of associated function `core::num::<impl isize>::max_value` that will be deprecated in a future Rust version: replaced by the `MAX` associated constant on this type
--> src/raw.rs:313:47
|
313 | ... if state > isize::max_value() as usize {
| ^^^^^^^^^
warning: use of associated function `core::num::<impl isize>::max_value` that will be deprecated in a future Rust version: replaced by the `MAX` associated constant on this type
--> src/raw.rs:343:27
|
343 | if state > isize::max_value() as usize {
|
```
```
warning: passing a unit value to a function
--> tests/panic.rs:134:44
|
134 | future::block_on(future::or(&mut task, future::ready(Default::default())));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(clippy::unit_arg)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
|
134 ~ future::block_on(future::or(&mut task, {
135 + Default::default();
136 + future::ready(())
137 ~ }));
|
warning: passing a unit value to a function
--> tests/panic.rs:200:52
|
200 | future::block_on(future::or(&mut task, future::ready(Default::default())));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
|
200 ~ future::block_on(future::or(&mut task, {
201 + Default::default();
202 + future::ready(())
203 ~ }));
|
```
```
warning: redundant clone
--> tests/waker_ready.rs:192:25
|
192 | let w2 = get_waker().clone();
| ^^^^^^^^ help: remove this
|
= note: `#[warn(clippy::redundant_clone)]` on by default
note: this value is dropped without further use
--> tests/waker_ready.rs:192:14
|
192 | let w2 = get_waker().clone();
| ^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
```