Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow iterating over audiences #9

Merged
merged 1 commit into from
May 27, 2024
Merged

Conversation

bittrance
Copy link
Contributor

I suspect that like me, the most common operator on OneOrMany is to check whether it contains a particular audience value. That currently is more verbose than it needs to be.

This PR allows getting an "read-only" iterator from a OneOrMany. This means that:

let valid = match jwt.claims().aud {
    jwtk::OneOrMany::One(ref aud) if aud == "my-aud" => true,
    jwtk::OneOrMany::Vec(ref auds) if auds.iter().any(|a| a == "my-aud") => true,
    _ => false,
};

becomes:

let valid = jwt.claims().aud.iter().any(|a| a == "my-aud");

Which I think is a small but significant improvement.

@blckngm blckngm merged commit caa712f into blckngm:main May 27, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants