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

Move clients::mutex to sync module #326

Merged
merged 4 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

**Breaking changes**:
- ([#325](https://github.com/ramsayleung/rspotify/pull/325)) The `auth_code`, `auth_code_pkce`, `client_creds`, `clients::base` and `clients::oauth` modules have been removed from the public API; you should access the same types from their parent modules instead
- ([#326](https://github.com/ramsayleung/rspotify/pull/326)) The `rspotify::clients::mutex` module has been renamed to `rspotify::sync`

## 0.11.5 (2022.03.28)

Expand Down
6 changes: 4 additions & 2 deletions src/auth_code.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{
auth_urls,
clients::{mutex::Mutex, BaseClient, OAuthClient},
clients::{BaseClient, OAuthClient},
http::{Form, HttpClient},
join_scopes, params, ClientResult, Config, Credentials, OAuth, Token,
join_scopes, params,
sync::Mutex,
ClientResult, Config, Credentials, OAuth, Token,
};

use std::collections::HashMap;
Expand Down
6 changes: 4 additions & 2 deletions src/auth_code_pkce.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::{
alphabets, auth_urls,
clients::{mutex::Mutex, BaseClient, OAuthClient},
clients::{BaseClient, OAuthClient},
generate_random_string,
http::{Form, HttpClient},
join_scopes, params, ClientResult, Config, Credentials, OAuth, Token,
join_scopes, params,
sync::Mutex,
ClientResult, Config, Credentials, OAuth, Token,
};

use std::collections::HashMap;
Expand Down
6 changes: 4 additions & 2 deletions src/client_creds.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{
clients::{mutex::Mutex, BaseClient},
clients::BaseClient,
http::{Form, HttpClient},
params, ClientResult, Config, Credentials, Token,
params,
sync::Mutex,
ClientResult, Config, Credentials, Token,
};

use maybe_async::maybe_async;
Expand Down
2 changes: 1 addition & 1 deletion src/clients/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::{
auth_urls,
clients::{
convert_result,
mutex::Mutex,
pagination::{paginate, Paginator},
},
http::{BaseHttpClient, Form, Headers, HttpClient, Query},
join_ids,
macros::build_map,
model::*,
sync::Mutex,
ClientResult, Config, Credentials, Token,
};

Expand Down
1 change: 0 additions & 1 deletion src/clients/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod base;
pub mod mutex;
mod oauth;
pub mod pagination;

Expand Down
18 changes: 0 additions & 18 deletions src/clients/mutex/futures.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/clients/mutex/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/clients/mutex/sync.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ mod auth_code;
mod auth_code_pkce;
mod client_creds;
pub mod clients;
pub mod sync;

// Subcrate re-exports
pub use rspotify_http as http;
Expand Down
1 change: 1 addition & 0 deletions src/sync/blocking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use std::sync::Mutex;
16 changes: 16 additions & 0 deletions src/sync/futures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[derive(Debug, Default)]
pub struct Mutex<T: ?Sized>(futures::lock::Mutex<T>);

#[derive(Debug)]
pub struct LockError;

impl<T> Mutex<T> {
pub fn new(val: T) -> Self {
Mutex(futures::lock::Mutex::new(val))
}

pub async fn lock(&self) -> Result<futures::lock::MutexGuard<'_, T>, LockError> {
let val = self.0.lock().await;
Ok(val)
}
}
16 changes: 16 additions & 0 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Synchronization primitives that have both synchronous and asynchronous variants under the same
//! interface.

#[cfg(feature = "__sync")]
mod blocking;
#[cfg(feature = "__async")]
mod futures;

#[cfg(feature = "__sync")]
use self::blocking as imp;
#[cfg(feature = "__async")]
use self::futures as imp;

/// A type alias for either an asynchronous mutex or [`std::sync::Mutex`], depending on whether
/// this library is compiled in asynchronous or synchronous mode.
pub type Mutex<T> = imp::Mutex<T>;