Why not return Pending
struct instead of impl Future<Output = Result<Response, Error>>
#2578
Closed
JadKHaddad
started this conversation in
General
Replies: 1 comment
-
It's for a similar reason why in Java or C# you might return an interface instead of a class, or similarly in any other language. Sure you can conceive of reasons you as a user might like the concrete type, there are also benefits to the library for only promising specific behavior of the return type. By returning an |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Why does
Client::execute(request: Request)
not simply return thePending
struct?:it returns
impl Future<Output = Result<Response, Error>>
Background
I am trying to pin the outgoing request in a struct that implements
Future
. Withtokio::sleep()
I can pin theSleep
struct returned by the function without usingPin<Box<dyn Future>>
. Is it a design decision to return animpl Future
and hide thePending
struct? Wouldn't it be helpful to return a concrete type instead?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions