Skip to content

Commit

Permalink
refactor!: remove multirequest methods (#20)
Browse files Browse the repository at this point in the history
Multirequest methods like `send_all` and `send_all_paginated` probably
make more sense as a user-implementation as there are conflicting
decisions in what the return type should be (single stream of results,
iterator of streams, etc). Single request queries are more unambiguous,
so we remove the multirequest feature and focus instead on great
single-request ergonomics, leaving the decision in how to send multiple
requests to the user.
  • Loading branch information
SebRollen authored Jan 11, 2022
1 parent fe8079c commit 6f42eda
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 185 deletions.
102 changes: 0 additions & 102 deletions examples/multiple_pagination.rs

This file was deleted.

28 changes: 0 additions & 28 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,6 @@ impl Client {
self.send_raw(req).await
}

/// Send multiple `Request`s, returing a stream of results
pub fn send_all<'a, I, R>(
&'a self,
requests: I,
) -> impl Stream<Item = Result<R::Response>> + Unpin + 'a
where
I: IntoIterator<Item = &'a R> + 'a,
R: Request + 'a,
{
Box::pin(
stream::iter(requests.into_iter())
.map(move |r| self.send(r).map_into())
.filter_map(|x| x),
)
}

/// Send a paginated request, returning a stream of results
pub fn send_paginated<'a, R: PaginatedRequest>(
&'a self,
Expand Down Expand Up @@ -221,16 +205,4 @@ impl Client {
},
))
}

/// Send multiple paginated requests, returning a stream of results
pub fn send_all_paginated<'a, I, R>(
&'a self,
requests: I,
) -> impl Iterator<Item = impl Stream<Item = Result<R::Response>> + 'a>
where
I: IntoIterator<Item = &'a R> + 'a,
R: PaginatedRequest + 'a,
{
requests.into_iter().map(move |r| self.send_paginated(r))
}
}
25 changes: 25 additions & 0 deletions src/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,28 @@ pub mod path {
}
}
}

//enum PaginationFn<T, U> {
// NoResult(Box<dyn Send + Sync + Fn(Option<&U>) -> Option<U>>),
// ResultNeeded(Box<dyn Send + Sync + Fn(Option<&U>, &T) -> Option<U>>),
//}
//
//impl<'u, T, U: 'u> From<fn(Option<&'u U>) -> Option<U>> for PaginationFn<T, U> {
// fn from(x: fn(Option<&'u U>) -> Option<U>) -> PaginationFn<T, U> {
// PaginationFn::NoResult(Box::new(x))
// }
//}
//
//impl<T: 'static, U: 'static> From<fn(Option<&U>, &T) -> Option<U>> for PaginationFn<T, U> {
// fn from(x: fn(Option<&U>, &T) -> Option<U>) -> PaginationFn<T, U> {
// PaginationFn::ResultNeeded(Box::new(x))
// }
//}
//
//fn test(x: Option<&i32>) -> Option<i32> {
// x.cloned()
//}
//
//fn new_pagination<T>() -> PaginationFn<T, i32> {
// test.into()
//}
1 change: 1 addition & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub trait Request {
type Data: Serialize;
/// The type of the response from the server.
type Response: for<'de> Deserialize<'de> + Unpin;

/// The HTTP method for the request.
const METHOD: Method = Method::GET;

Expand Down
1 change: 0 additions & 1 deletion tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod authorization;
mod data;
mod empty_response;
mod errors;
mod multiple_queries;
mod pagination;
mod post;
mod utils;
54 changes: 0 additions & 54 deletions tests/integration/multiple_queries.rs

This file was deleted.

0 comments on commit 6f42eda

Please sign in to comment.