Skip to content

Commit

Permalink
extract the complex type
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain Jiang committed Nov 9, 2023
1 parent c7c02e5 commit b6201ab
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions service-async/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<Request, Response, E> BoxedService<Request, Response, E> {
/// # Safety
/// If you are sure the inner type is T, you can downcast it.
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
&*(self.svc as *const () as *const T)
&*(self.svc as *const T)
}
}

Expand Down Expand Up @@ -80,15 +80,17 @@ where
}
}

type BoxedFuture<T, E> = Pin<Box<dyn Future<Output = Result<T, E>>>>;

struct ServiceVtable<T, U, E> {
call: unsafe fn(raw: *const (), req: T) -> Pin<Box<dyn Future<Output = Result<U, E>>>>,
call: unsafe fn(raw: *const (), req: T) -> BoxedFuture<U,E>,
drop: unsafe fn(raw: *const ()),
}

unsafe fn call<R, S>(
svc: *const (),
req: R,
) -> Pin<Box<dyn Future<Output = Result<S::Response, S::Error>>>>
) -> BoxedFuture<S::Response, S::Error>
where
R: 'static,
S: Service<R> + 'static,
Expand Down

0 comments on commit b6201ab

Please sign in to comment.