fix(bindings): Reduce scope of RwLock read lock
Fixes a clippy lint.
@@ -97,8 +97,11 @@ impl AuthenticationService {
username: String,
password: String,
) -> Result<Arc<Client>, AuthenticationError> {
- match self.client.read().unwrap().as_ref() {
- Some(client) => {
+ let client = match &*self.client.read().unwrap() {
+ Some(client) => client.clone(),
+ None => return Err(AuthenticationError::ClientMissing),
+ };
+
// Login and ask the server for the full user ID as this could be different from
// the username that was entered.
client.login(username, password).map_err(AuthenticationError::from)?;
@@ -115,13 +118,8 @@ impl AuthenticationService {
.map_err(AuthenticationError::from)?;
// Restore the client using the session from the login request.
- client
- .restore_session(session)
- .map(|_| client.clone())
- .map_err(AuthenticationError::from)
- }
- None => Err(AuthenticationError::ClientMissing),
- }
+ client.restore_session(session).map_err(AuthenticationError::from)?;
+ Ok(client)
}
/// Restore an existing session on the current homeserver using an access
@@ -136,8 +134,11 @@ impl AuthenticationService {
token: String,
device_id: String,
) -> Result<Arc<Client>, AuthenticationError> {
- match self.client.read().unwrap().as_ref() {
- Some(client) => {
+ let client = match &*self.client.read().unwrap() {
+ Some(client) => client.clone(),
+ None => return Err(AuthenticationError::ClientMissing),
+ };
+
// Restore the client and ask the server for the full user ID as this
// could be different from the username that was entered.
let discovery_user_id = UserId::parse("@unknown:unknown")
@@ -170,13 +171,8 @@ impl AuthenticationService {
.map_err(AuthenticationError::from)?;
// Restore the client using the session.
- client
- .restore_session(session)
- .map(|_| client.clone())
- .map_err(AuthenticationError::from)
- }
- None => Err(AuthenticationError::ClientMissing),
- }
+ client.restore_session(session).map_err(AuthenticationError::from)?;
+ Ok(client)
}
/// Get the homeserver login details from a client.
