diff options
| author | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-07-02 18:55:42 +0200 |
|---|---|---|
| committer | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-07-02 18:55:42 +0200 |
| commit | cb2c7570db807eab35b3decd813f5cbec844ddb3 (patch) | |
| tree | c5c1cd246bff5e9dfc585492ecc1ff0f77cff66e /src/libcore/future | |
| parent | 9eee0d2288c067be081f2ca35f5b2d3cfc95fcf2 (diff) | |
| download | rust-cb2c7570db807eab35b3decd813f5cbec844ddb3.tar.gz rust-cb2c7570db807eab35b3decd813f5cbec844ddb3.zip | |
Add explanation for custom trait object
Diffstat (limited to 'src/libcore/future')
| -rw-r--r-- | src/libcore/future/future_obj.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libcore/future/future_obj.rs b/src/libcore/future/future_obj.rs index 86fe9825ded..173e381ca50 100644 --- a/src/libcore/future/future_obj.rs +++ b/src/libcore/future/future_obj.rs @@ -20,7 +20,15 @@ use task::{Context, Poll}; /// A custom trait object for polling futures, roughly akin to /// `Box<dyn Future<Output = T> + 'a>`. -/// Contrary to `FutureObj`, `LocalFutureObj` does not have a `Send` bound. +/// +/// This custom trait object was introduced for two reasons: +/// - Currently it is not possible to take `dyn Trait` by value and +/// `Box<dyn Trait>` is not available in no_std contexts. +/// - The `Future` trait is currently not object safe: The `Future::poll` +/// method makes uses the arbitrary self types feature and traits in which +/// this feature is used are currently not object safe due to current compiler +/// limitations. (See tracking issue for arbitray self types for more +/// information #44874) pub struct LocalFutureObj<'a, T> { ptr: *mut (), poll_fn: unsafe fn(*mut (), &mut Context) -> Poll<T>, @@ -87,6 +95,15 @@ impl<'a, T> Drop for LocalFutureObj<'a, T> { /// A custom trait object for polling futures, roughly akin to /// `Box<dyn Future<Output = T> + Send + 'a>`. +/// +/// This custom trait object was introduced for two reasons: +/// - Currently it is not possible to take `dyn Trait` by value and +/// `Box<dyn Trait>` is not available in no_std contexts. +/// - The `Future` trait is currently not object safe: The `Future::poll` +/// method makes uses the arbitrary self types feature and traits in which +/// this feature is used are currently not object safe due to current compiler +/// limitations. (See tracking issue for arbitray self types for more +/// information #44874) pub struct FutureObj<'a, T>(LocalFutureObj<'a, T>); unsafe impl<'a, T> Send for FutureObj<'a, T> {} |
