Skip to content

Commit

Permalink
Merge branch 'master' into ramsay_fix_playlist_add_item
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsayleung committed May 14, 2023
2 parents 2789b51 + 580c220 commit 7bc84d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 0.12 (unreleased )
**New features**
- ([#390](https://github.com/ramsayleung/rspotify/pull/390)) The `scopes!` macro supports to split the scope by whitespace.

**Breaking changes**
- ([#409](https://github.com/ramsayleung/rspotify/pull/409)) Change type of `position` parameter in `playlist_add_items` endpoint from `Opinion<Duration>` to `Opinion<u32>`

Expand Down
27 changes: 26 additions & 1 deletion rspotify-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@
/// manually.insert("playlist-read-collaborative".to_owned());
/// assert_eq!(with_macro, manually);
/// ```
/// Note: the scopes! macro also support to split the word by whitespace
/// so the scope can't contain any whitespace
/// ```
/// use rspotify_macros::scopes;
/// use std::collections::HashSet;
///
/// let macro_with_whitespace = scopes!("playlist-read-private playlist-read-collaborative");
/// let mut manually = HashSet::new();
/// manually.insert("playlist-read-private".to_owned());
/// manually.insert("playlist-read-collaborative".to_owned());
/// assert_eq!(macro_with_whitespace, manually);
/// ```
#[macro_export]
macro_rules! scopes {
($($key:expr),*) => {{
let mut container = ::std::collections::HashSet::new();
$(
container.insert($key.to_owned());
for scope in $key.split_whitespace(){
container.insert(scope.to_owned());
}
)*
container
}};
Expand All @@ -37,4 +51,15 @@ mod test {
assert!(scopes.contains("foo"));
assert!(scopes.contains("bar"));
}

#[test]
fn test_scopes_with_whitespace() {
let scopes = scopes!(" hello world foo bar");

assert_eq!(scopes.len(), 4);
assert!(scopes.contains("hello"));
assert!(scopes.contains("world"));
assert!(scopes.contains("foo"));
assert!(scopes.contains("bar"));
}
}

0 comments on commit 7bc84d1

Please sign in to comment.