Choosing the right way to write an API wrapper

Hi everyone! :slight_smile:


Since I'm a new user, I can only include two links, so the /blob/... things are the suffixes to

So as a learning project, I'm writing a wrapper for some Steam API endpoints but I've encountered some decisions I have to make that I'm really not sure about, and that's where I need help.

I already wrote some code that takes N URLs and returns a Vec of N results but now I want to make this more useable by returning a Stream (from the futures crate) that will yield the results.

I created a repository where I rebuilt my problem using an example API, there are also tests that capture the problem I'm trying to solve.

In this example, I'm querying a dummy-API with a search term, the API then returns some products that match the query.
I want to return a struct that contains the search-term (borrowed, not owned), that was used to make the request, and the actual response from the API.


So far so good, now when I return a stream that is built just with the StreamExt methods


I have the problem that rust-analyer won't annotate the type when iterating over the results like this


which is not nice. When iterating over the results like this, the type is correctly annotated


While trying to solve this problem I came up with this


which basically just wraps the thing I've done before in a struct, but now the type annotation of rust-analyzer works with both ways of iterating over the results.

My questions are

  1. Why does rust-analyer fail in the aforementioned case even though
    • Next::Ouput = Option<St::Item> and
    • St::Item = QueryResult<'a>
  2. Is one of the two ways I'm trying to write the API-wrapper preferred over the other?
    • Or is the preferred way of doing this something else that I didn't think of?

Thanks a lot everyone!