From 168874e0f489e2f2e0d5679b9cedd63008a63ffe Mon Sep 17 00:00:00 2001 From: Gnome! <45660393+GnomedDev@users.noreply.github.com> Date: Tue, 31 May 2022 00:03:06 +0100 Subject: [PATCH] Remove unneeded `futures::iter::stream` usage (#1922) --- src/model/guild/mod.rs | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index 225b48d8f9c..8304e51c43d 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -14,8 +14,6 @@ mod scheduled_event; mod system_channel; mod welcome_screen; -#[cfg(feature = "model")] -use futures::stream::StreamExt; use serde::de::Error as DeError; #[cfg(feature = "model")] use tracing::error; @@ -1754,7 +1752,8 @@ impl Guild { /// **Note**: This will only search members that are cached. If you want to /// search all members in the guild via the Http API, use /// [`Self::search_members`]. - pub async fn members_starting_with( + #[must_use] + pub fn members_starting_with( &self, prefix: &str, case_sensitive: bool, @@ -1765,8 +1764,10 @@ impl Guild { || !case_sensitive && starts_with_case_insensitive(name, prefix) } - let mut members = futures::stream::iter(self.members.values()) - .filter_map(|member| async move { + let mut members = self + .members + .values() + .filter_map(|member| { let username = &member.user.name; if starts_with(prefix, case_sensitive, username) { @@ -1784,8 +1785,7 @@ impl Guild { } } }) - .collect::>() - .await; + .collect::>(); if sorted { members.sort_by(|a, b| closest_to_origin(prefix, &a.1[..], &b.1[..])); @@ -1826,7 +1826,8 @@ impl Guild { /// **Note**: This will only search members that are cached. If you want to /// search all members in the guild via the Http API, use /// [`Self::search_members`]. - pub async fn members_containing( + #[must_use] + pub fn members_containing( &self, substring: &str, case_sensitive: bool, @@ -1837,8 +1838,10 @@ impl Guild { || !case_sensitive && contains_case_insensitive(name, substring) } - let mut members = futures::stream::iter(self.members.values()) - .filter_map(|member| async move { + let mut members = self + .members + .values() + .filter_map(|member| { let username = &member.user.name; if contains(substring, case_sensitive, username) { @@ -1856,8 +1859,7 @@ impl Guild { } } }) - .collect::>() - .await; + .collect::>(); if sorted { members.sort_by(|a, b| closest_to_origin(substring, &a.1[..], &b.1[..])); @@ -1893,14 +1895,17 @@ impl Guild { /// **Note**: This will only search members that are cached. If you want to /// search all members in the guild via the Http API, use /// [`Self::search_members`]. - pub async fn members_username_containing( + #[must_use] + pub fn members_username_containing( &self, substring: &str, case_sensitive: bool, sorted: bool, ) -> Vec<(&Member, String)> { - let mut members = futures::stream::iter(self.members.values()) - .filter_map(|member| async move { + let mut members = self + .members + .values() + .filter_map(|member| { let name = &member.user.name; if (case_sensitive && name.contains(substring)) @@ -1911,8 +1916,7 @@ impl Guild { None } }) - .collect::>() - .await; + .collect::>(); if sorted { members.sort_by(|a, b| closest_to_origin(substring, &a.1[..], &b.1[..])); @@ -1951,14 +1955,17 @@ impl Guild { /// **Note**: This will only search members that are cached. If you want to /// search all members in the guild via the Http API, use /// [`Self::search_members`]. - pub async fn members_nick_containing( + #[must_use] + pub fn members_nick_containing( &self, substring: &str, case_sensitive: bool, sorted: bool, ) -> Vec<(&Member, String)> { - let mut members = futures::stream::iter(self.members.values()) - .filter_map(|member| async move { + let mut members = self + .members + .values() + .filter_map(|member| { let nick = match member.nick { Some(ref nick) => nick.to_string(), None => member.user.name.to_string(), @@ -1972,8 +1979,7 @@ impl Guild { None } }) - .collect::>() - .await; + .collect::>(); if sorted { members.sort_by(|a, b| closest_to_origin(substring, &a.1[..], &b.1[..]));