mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-25 23:45:52 +03:00
[GH-ISSUE #382] Make search function generic over search types #118
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#118
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @alevani on GitHub (Jan 10, 2023).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/382
Using 0.11.6
I would like to be able to deserialise the search result into a specific search type. Right now the
search()function onClientCredsSpotifyreturns aSearchResultby default.Motivations:
The
SearchResultwe get back is anenumthat you can only extract data from with pattern matching orif-letstatement.If you know what search result you expect, this feels like an extra step
I have seen that you have some unused types such as
SearchPlaylists. I would suggest makingsearch()generic over these types to be able to extract the data more easily. I have been able to go a bit of the wayThis works well when specifying a search result type, or when implicitly inferring the type. However, I think the
search()function should still return aSearchResultstype if no types were inferred by::<>. My view is that it should default toSearchResultwhen called likeOr return T when use like this
Unfortunately, I haven't found a good way to infer the default generic type, and fail to find a neat solution to avoid deserialisation problems.
Describe alternatives you've considered
Changing the
SearchResultto a struct with optional fields makes you able to extract the values:But doesn't seem like the most Rust way to do things
@github-actions[bot] commented on GitHub (Jun 24, 2023):
Message to comment on stale issues. If none provided, will not mark issues stale
RSPOTIFY_#255