Skip to content

Commit

Permalink
[fix] Change output params from Vec<...> to impl IntoIterator (#3740)
Browse files Browse the repository at this point in the history
Signed-off-by: VAmuzing <[email protected]>
  • Loading branch information
VAmuzing committed Nov 6, 2023
1 parent fca1d51 commit ed4fc40
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl Client {
.join(uri::PENDING_TRANSACTIONS)
.expect("Valid URI"),
)
.params(&pagination)
.params(pagination.clone())
.headers(self.headers.clone())
.build()?
.send()?;
Expand Down
13 changes: 8 additions & 5 deletions data_model/src/query/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ pub struct Pagination {
}

impl Pagination {
/// Converts self to Vec of tuples to be used in queries
/// Converts self to iterator of tuples to be used in queries
///
/// The length of the output Vec is not constant and it's in (0..3)
pub fn into_query_parameters(self) -> Vec<(&'static str, NonZeroU64)> {
match (self.start, self.limit) {
/// The length of the output iterator is not constant and it's in (0..3)
pub fn into_query_parameters(
self,
) -> impl IntoIterator<Item = (&'static str, NonZeroU64)> + Clone {
let result_vec = match (self.start, self.limit) {
(Some(start), Some(limit)) => {
vec![(PAGINATION_LIMIT, limit.into()), (PAGINATION_START, start)]
}
(Some(start), None) => vec![(PAGINATION_START, start)],
(None, Some(limit)) => vec![(PAGINATION_LIMIT, limit.into())],
(None, None) => Vec::new(),
}
};
result_vec.into_iter()
}
}

Expand Down
9 changes: 5 additions & 4 deletions data_model/src/query/sorting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ impl Sorting {
}

impl Sorting {
/// Converts self to Vec of tuples to be used in queries
/// Converts self to iterator of tuples to be used in queries
///
/// The length of the output Vec is not constant and it's in (0..3)
pub fn into_query_parameters(self) -> Vec<(&'static str, Name)> {
/// The length of the output iterator is not constant and has either 0 or 1 value
pub fn into_query_parameters(self) -> impl IntoIterator<Item = (&'static str, Name)> + Clone {
self.sort_by_metadata_key
.map_or(Vec::new(), |key| vec![(SORT_BY_KEY, key)])
.map(|key| (SORT_BY_KEY, key))
.into_iter()
}
}

Expand Down

0 comments on commit ed4fc40

Please sign in to comment.