Skip to content

Commit cb2c757

Browse files
Add explanation for custom trait object
1 parent 9eee0d2 commit cb2c757

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/libcore/future/future_obj.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ use task::{Context, Poll};
2020

2121
/// A custom trait object for polling futures, roughly akin to
2222
/// `Box<dyn Future<Output = T> + 'a>`.
23-
/// Contrary to `FutureObj`, `LocalFutureObj` does not have a `Send` bound.
23+
///
24+
/// This custom trait object was introduced for two reasons:
25+
/// - Currently it is not possible to take `dyn Trait` by value and
26+
/// `Box<dyn Trait>` is not available in no_std contexts.
27+
/// - The `Future` trait is currently not object safe: The `Future::poll`
28+
/// method makes uses the arbitrary self types feature and traits in which
29+
/// this feature is used are currently not object safe due to current compiler
30+
/// limitations. (See tracking issue for arbitray self types for more
31+
/// information #44874)
2432
pub struct LocalFutureObj<'a, T> {
2533
ptr: *mut (),
2634
poll_fn: unsafe fn(*mut (), &mut Context) -> Poll<T>,
@@ -87,6 +95,15 @@ impl<'a, T> Drop for LocalFutureObj<'a, T> {
8795

8896
/// A custom trait object for polling futures, roughly akin to
8997
/// `Box<dyn Future<Output = T> + Send + 'a>`.
98+
///
99+
/// This custom trait object was introduced for two reasons:
100+
/// - Currently it is not possible to take `dyn Trait` by value and
101+
/// `Box<dyn Trait>` is not available in no_std contexts.
102+
/// - The `Future` trait is currently not object safe: The `Future::poll`
103+
/// method makes uses the arbitrary self types feature and traits in which
104+
/// this feature is used are currently not object safe due to current compiler
105+
/// limitations. (See tracking issue for arbitray self types for more
106+
/// information #44874)
90107
pub struct FutureObj<'a, T>(LocalFutureObj<'a, T>);
91108

92109
unsafe impl<'a, T> Send for FutureObj<'a, T> {}

0 commit comments

Comments
 (0)