From 68db038336573d680b7fe7f8227b9cbbdbc2f131 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Mon, 23 Nov 2020 19:54:16 +0000 Subject: [PATCH] Properly avoid allocation for our_username in resync command. --- src/commands/management.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/commands/management.rs b/src/commands/management.rs index a8e38f5..564a59f 100644 --- a/src/commands/management.rs +++ b/src/commands/management.rs @@ -3,7 +3,7 @@ use crate::context::Context; use crate::db::errors::DataError; use crate::matrix; use async_trait::async_trait; -use matrix_sdk::identifiers::RoomId; +use matrix_sdk::identifiers::{RoomId, UserId}; use std::convert::TryFrom; pub struct ResyncCommand; @@ -18,16 +18,14 @@ impl Command for ResyncCommand { async fn execute(&self, ctx: &Context<'_>) -> Execution { let room_id = RoomId::try_from(ctx.room_id).expect("failed to decode room ID"); - let our_username = match ctx.matrix_client.user_id().await { - Some(username) => username.as_str().to_owned(), - _ => "".to_owned(), - }; + let our_username: Option = ctx.matrix_client.user_id().await; + let our_username: &str = our_username.as_ref().map_or("", UserId::as_str); let usernames = matrix::get_users_in_room(&ctx.matrix_client, &room_id).await; let result: ResyncResult = usernames .into_iter() - .filter(|username| username != &our_username) + .filter(|username| username != our_username) .map(|username| ctx.db.rooms.add_user_to_room(&username, room_id.as_str())) .collect(); //Make use of collect impl on Result.