Skip to content

Commit

Permalink
feat: add Sync to pagination types
Browse files Browse the repository at this point in the history
  • Loading branch information
sirewix committed Jan 17, 2025
1 parent 8971153 commit 7eb1aa2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/v2/management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Zitadel {
pub fn search_actions(
&self,
body: ListActionsRequest,
) -> Result<impl Stream<Item = V1Action> + Send> {
) -> Result<impl Stream<Item = V1Action> + Send + Sync> {
Ok(PaginationHandler::<_, V1Action>::new(
self.clone(),
body,
Expand Down
16 changes: 8 additions & 8 deletions src/v2/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ pub(crate) trait PaginationRequest {
fn page_size(&self) -> usize;
}

type DataFuture<T> = dyn Future<Output = Result<Vec<T>>> + Send;
type DataFuture<T> = dyn Future<Output = Result<Vec<T>>> + Send + Sync;

pub(crate) struct PaginationHandler<Q, T>
where
Q: Serialize + Send,
Q: Serialize + Send + Sync,
T: DeserializeOwned + 'static,
{
zitadel: Zitadel,
query: Box<dyn PaginationRequest<Item = Q> + Send>,
query: Box<dyn PaginationRequest<Item = Q> + Send + Sync>,
endpoint: Url,
page: usize,
buffer: Vec<T>,
Expand All @@ -48,12 +48,12 @@ where

impl<Q, T> PaginationHandler<Q, T>
where
Q: Serialize + Send + 'static,
Q: Serialize + Send + Sync + 'static,
T: DeserializeOwned + 'static,
{
pub(crate) fn new(
zitadel: Zitadel,
query: impl PaginationRequest<Item = Q> + Send + 'static,
query: impl PaginationRequest<Item = Q> + Send + Sync + 'static,
endpoint: Url,
) -> Self {
let page = 0;
Expand All @@ -72,7 +72,7 @@ where

async fn get_more_data<T: DeserializeOwned + 'static>(
zitadel: Zitadel,
query: impl Serialize + Send,
query: impl Serialize + Send + Sync,
endpoint: Url,
) -> Result<Vec<T>> {
let request = zitadel
Expand All @@ -88,14 +88,14 @@ async fn get_more_data<T: DeserializeOwned + 'static>(

impl<Q, T> Unpin for PaginationHandler<Q, T>
where
Q: Serialize + Send + 'static,
Q: Serialize + Send + Sync + 'static,
T: DeserializeOwned + 'static,
{
}

impl<Q, T> Stream for PaginationHandler<Q, T>
where
Q: Serialize + Send + 'static,
Q: Serialize + Send + Sync + 'static,
T: DeserializeOwned + 'static,
{
type Item = T;
Expand Down
9 changes: 6 additions & 3 deletions src/v2/users/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Zitadel {
&self,
user_id: &str,
body: UserServiceListIdpLinksBody,
) -> Result<impl Stream<Item = IdpLink> + Send> {
) -> Result<impl Stream<Item = IdpLink> + Send + Sync> {
Ok(PaginationHandler::<_, IdpLink>::new(
self.clone(),
body,
Expand All @@ -172,7 +172,10 @@ impl Zitadel {
/// Search Users
/// Search for users. By default, we will return users of your organization.
/// Make sure to include a limit and sorting for pagination.
pub fn list_users(&self, body: ListUsersRequest) -> Result<impl Stream<Item = User> + Send> {
pub fn list_users(
&self,
body: ListUsersRequest,
) -> Result<impl Stream<Item = User> + Send + Sync> {
Ok(PaginationHandler::<_, User>::new(self.clone(), body, self.make_url("/v2/users")?))
}
/// Lock user
Expand Down Expand Up @@ -668,7 +671,7 @@ impl Zitadel {
&self,
user_id: &str,
body: ListUserMetadataRequest,
) -> Result<impl Stream<Item = UserMetadataResponse> + Send> {
) -> Result<impl Stream<Item = UserMetadataResponse> + Send + Sync> {
Ok(PaginationHandler::<_, UserMetadataResponse>::new(
self.clone(),
body,
Expand Down

0 comments on commit 7eb1aa2

Please sign in to comment.