InputUsername / listenbrainz-rs

ListenBrainz API bindings for Rust
https://crates.io/crates/listenbrainz
MIT License
12 stars 6 forks source link

Enforce authentication statically for ListenBrainz client #8

Open InputUsername opened 3 years ago

InputUsername commented 3 years ago

We can use the "typestate pattern" to enforce authentication at compile time. To do this, we can make the ListenBrainz type generic over authentication status using a marker trait (eg. AuthStatus). A ListenBrainz<NotAuthenticated> instance then first has to be authenticated to obtain a ListenBrainz<Authenticated>, which can perform methods that require authentication.

I've implemented a proof-of-concept of this in the feature/static-auth branch.

Thoughts?

shymega commented 1 year ago

I really like this approach. Would you like me to rebase the branch against mainline?

Thinking of using the same approach for my Rust crate for Starling Bank.

InputUsername commented 1 year ago

Would you like me to rebase the branch against mainline?

Sure, go ahead. I'm very busy at the moment but I might have time to look into it soon.