pub struct TaskHandle<T>(Option<T>)
where
T: crate::TaskHandle;
impl<T> Drop for TaskHandle<T>
where
T: crate::TaskHandle,
{
fn drop(&mut self) {
if self.0.is_some() {
panic!("Should be cancelled, joined or detached, before dropping.");
}
}
}
impl<T> crate::TaskHandle for TaskHandle<T>
where
T: crate::TaskHandle,
{
type Output = T::Output;
type JoinError = T::JoinError;
fn join(mut self) -> impl Future<Output = Result<Self::Output, Self::JoinError>> {
self.0.take().unwrap().join()
}
fn abort(mut self) {
self.0.take().unwrap().abort();
}
fn cancel(mut self) -> impl Future<Output = ()> {
self.0.take().unwrap().cancel()
}
fn detach(mut self) {
self.0.take().unwrap().detach();
}
}
impl<T> From<T> for TaskHandle<T>
where
T: crate::TaskHandle,
{
fn from(value: T) -> Self {
Self(Some(value))
}
}
#[derive(Debug)]
pub struct Infallible {}
impl std::fmt::Display for Infallible {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Infallible.")
}
}
impl std::error::Error for Infallible {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}