[PR #331] [MERGED] Implement Into<&'static str> for all enums #402

Closed
opened 2026-02-27 20:24:35 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/331
Author: @SabrinaJewson
Created: 6/15/2022
Status: Merged
Merged: 6/25/2022
Merged by: @marioortizmanero

Base: masterHead: into-static-str


📝 Commits (7)

  • 88926ae Implement Into<&'static str> for all enums
  • 0c91853 Update changelog
  • 2c21f32 Merge branch 'master' into into-static-str
  • 5c6a229 Remove AsRef<str> implementations
  • 92637b3 Update examples
  • 67b95b1 Update Reqwest examples
  • 2efbbad Update changelog

📊 Changes

12 files changed (+147 additions, -146 deletions)

View changed files

📝 CHANGELOG.md (+4 -0)
📝 examples/auth_code.rs (+1 -1)
📝 examples/ureq/search.rs (+9 -9)
📝 rspotify-model/src/enums/country.rs (+2 -2)
📝 rspotify-model/src/enums/misc.rs (+13 -13)
📝 rspotify-model/src/enums/types.rs (+10 -10)
📝 rspotify-model/src/recommend.rs (+2 -2)
📝 src/clients/base.rs (+47 -50)
📝 src/clients/oauth.rs (+28 -28)
📝 tests/test_enums.rs (+12 -12)
📝 tests/test_with_credential.rs (+3 -3)
📝 tests/test_with_oauth.rs (+16 -16)

📄 Description

Description

Derives both AsRef<str> and Into<&'static str> (via From<{the enum}> for &'static str) for all the enums.

Note: there’s a #[derive] in here that rustfmt explodes on to 13 lines. I don’t really like it but I also can’t separate the derives into two lines because rustfmt just merges them together again 😄

Also makes Market Copy, just so I can avoid code duplication between AsRef<str> and From<Market> for &'static str.

Motivation and Context

This makes the enums useful in more places, since the lifetime of the string is not actually tied to the lifetime of the enum.

Dependencies

None.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Please also list any relevant details for your test configuration

  • Test A: cargo test -p rspotify-model

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/331 **Author:** [@SabrinaJewson](https://github.com/SabrinaJewson) **Created:** 6/15/2022 **Status:** ✅ Merged **Merged:** 6/25/2022 **Merged by:** [@marioortizmanero](https://github.com/marioortizmanero) **Base:** `master` ← **Head:** `into-static-str` --- ### 📝 Commits (7) - [`88926ae`](https://github.com/ramsayleung/rspotify/commit/88926aeb32cae4cc867daa78ee49e1fc672e520f) Implement `Into<&'static str>` for all enums - [`0c91853`](https://github.com/ramsayleung/rspotify/commit/0c91853ddaaaeabdb2538d54cb625c40f1359f80) Update changelog - [`2c21f32`](https://github.com/ramsayleung/rspotify/commit/2c21f32960ae9acadc0fee7db8a7fad591c75b02) Merge branch 'master' into into-static-str - [`5c6a229`](https://github.com/ramsayleung/rspotify/commit/5c6a229f26813cce7c8aa966e5b3b4d352ba95e9) Remove `AsRef<str>` implementations - [`92637b3`](https://github.com/ramsayleung/rspotify/commit/92637b3fbf577fe6423434d05c8d069faa2ba9e5) Update examples - [`67b95b1`](https://github.com/ramsayleung/rspotify/commit/67b95b1ff2d7e2b6d50369b96e581e67f2039987) Update Reqwest examples - [`2efbbad`](https://github.com/ramsayleung/rspotify/commit/2efbbad3f0d0fd15b22529c83a2a33c619cec7d6) Update changelog ### 📊 Changes **12 files changed** (+147 additions, -146 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+4 -0) 📝 `examples/auth_code.rs` (+1 -1) 📝 `examples/ureq/search.rs` (+9 -9) 📝 `rspotify-model/src/enums/country.rs` (+2 -2) 📝 `rspotify-model/src/enums/misc.rs` (+13 -13) 📝 `rspotify-model/src/enums/types.rs` (+10 -10) 📝 `rspotify-model/src/recommend.rs` (+2 -2) 📝 `src/clients/base.rs` (+47 -50) 📝 `src/clients/oauth.rs` (+28 -28) 📝 `tests/test_enums.rs` (+12 -12) 📝 `tests/test_with_credential.rs` (+3 -3) 📝 `tests/test_with_oauth.rs` (+16 -16) </details> ### 📄 Description ## Description Derives both `AsRef<str>` and `Into<&'static str>` (via `From<{the enum}> for &'static str`) for all the enums. Note: there’s a `#[derive]` in here that `rustfmt` explodes on to 13 lines. I don’t really like it but I also can’t separate the derives into two lines because rustfmt just merges them together again 😄 Also makes `Market` `Copy`, just so I can avoid code duplication between `AsRef<str>` and `From<Market> for &'static str`. ## Motivation and Context This makes the enums useful in more places, since the lifetime of the string is not actually tied to the lifetime of the enum. ## Dependencies None. ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) ## How has this been tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration - [x] Test A: `cargo test -p rspotify-model` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:35 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#402
No description provided.