Introduce HttpSend trait for converting Request -> Response

Parameterize everything that involves sending HTTP requests with the `H:
HttpSend` bound. This will allow us to swap out `HttpSend`
implementations when necessary, in order to better test our code
This commit is contained in:
Paul Woolcock
2018-08-23 21:46:31 -04:00
parent 6c2ebc6136
commit 49a2237803
6 changed files with 161 additions and 88 deletions
+6 -5
View File
@@ -1,4 +1,5 @@
use page::Page;
use http_send::HttpSend;
use serde::Deserialize;
/// Abstracts away the `next_page` logic into a single stream of items
@@ -23,15 +24,15 @@ use serde::Deserialize;
/// # Ok(())
/// # }
/// ```
pub(crate) struct ItemsIter<'a, T: Clone + for<'de> Deserialize<'de>> {
page: Page<'a, T>,
pub(crate) struct ItemsIter<'a, T: Clone + for<'de> Deserialize<'de>, H: 'a + HttpSend> {
page: Page<'a, T, H>,
buffer: Vec<T>,
cur_idx: usize,
use_initial: bool,
}
impl<'a, T: Clone + for<'de> Deserialize<'de>> ItemsIter<'a, T> {
pub(crate) fn new(page: Page<'a, T>) -> ItemsIter<'a, T> {
impl<'a, T: Clone + for<'de> Deserialize<'de>, H: HttpSend> ItemsIter<'a, T, H> {
pub(crate) fn new(page: Page<'a, T, H>) -> ItemsIter<'a, T, H> {
ItemsIter {
page,
buffer: vec![],
@@ -60,7 +61,7 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>> ItemsIter<'a, T> {
}
}
impl<'a, T: Clone + for<'de> Deserialize<'de>> Iterator for ItemsIter<'a, T> {
impl<'a, T: Clone + for<'de> Deserialize<'de>, H: HttpSend> Iterator for ItemsIter<'a, T, H> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {