[fractal/remove-clippy-warnings: 4/7] clippy: Use `type` definition for async channel types
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/remove-clippy-warnings: 4/7] clippy: Use `type` definition for async channel types
- Date: Mon, 6 Jul 2020 06:04:47 +0000 (UTC)
commit 78325f3629f64bb4a499dd22fe01872a881fd8cb
Author: Daniel GarcĂa Moreno <dani danigm net>
Date: Fri Jul 3 15:09:11 2020 +0200
clippy: Use `type` definition for async channel types
https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
fractal-gtk/src/actions/message.rs | 6 +++---
fractal-gtk/src/appop/notify.rs | 2 +-
fractal-gtk/src/backend/media.rs | 11 +++++++----
fractal-gtk/src/backend/user.rs | 4 +++-
fractal-gtk/src/widgets/image.rs | 5 +----
fractal-gtk/src/widgets/inline_player.rs | 5 +----
fractal-gtk/src/widgets/media_viewer.rs | 5 +----
7 files changed, 17 insertions(+), 21 deletions(-)
---
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index dc6be47e..54153cbc 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -144,7 +144,7 @@ pub fn new(
let name = m.body;
let url = m.url.unwrap_or_default();
- let (tx, rx): (Sender<Result<String, Error>>, Receiver<Result<String, Error>>) = channel();
+ let (tx, rx): (Sender<media::MediaResult>, Receiver<media::MediaResult>) = channel();
media::get_media_async(thread_pool.clone(), server_url.clone(), url, tx);
let parent_weak = parent_weak.clone();
@@ -182,8 +182,8 @@ pub fn new(
let url = m.url.unwrap_or_default();
let (tx, rx): (
- Sender<Result<String, Error>>,
- Receiver<Result<String, Error>>,
+ Sender<media::MediaResult>,
+ Receiver<media::MediaResult>,
) = channel();
media::get_media_async(thread_pool.clone(), server_url.clone(), url, tx);
diff --git a/fractal-gtk/src/appop/notify.rs b/fractal-gtk/src/appop/notify.rs
index c9e59f4f..926cbc45 100644
--- a/fractal-gtk/src/appop/notify.rs
+++ b/fractal-gtk/src/appop/notify.rs
@@ -61,7 +61,7 @@ impl AppOp {
String::new()
};
- let (tx, rx): (Sender<(String, String)>, Receiver<(String, String)>) = channel();
+ let (tx, rx): (Sender<user::UserInfo>, Receiver<user::UserInfo>) = channel();
user::get_user_info_async(
self.thread_pool.clone(),
self.user_info_cache.clone(),
diff --git a/fractal-gtk/src/backend/media.rs b/fractal-gtk/src/backend/media.rs
index c29362b5..44c2ba61 100644
--- a/fractal-gtk/src/backend/media.rs
+++ b/fractal-gtk/src/backend/media.rs
@@ -17,11 +17,14 @@ use fractal_api::r0::message::get_message_events::Response as GetMessagesEventsR
use super::{dw_media, get_prev_batch_from, ContentType, ThreadPool};
+pub type MediaResult = Result<String, Error>;
+pub type MediaList = (Vec<Message>, String);
+
pub fn get_thumb_async(
thread_pool: ThreadPool,
baseu: Url,
media: String,
- tx: Sender<Result<String, Error>>,
+ tx: Sender<MediaResult>,
) {
thread_pool.run(move || {
let fname = dw_media(baseu, &media, ContentType::default_thumbnail(), None);
@@ -33,7 +36,7 @@ pub fn get_media_async(
thread_pool: ThreadPool,
baseu: Url,
media: String,
- tx: Sender<Result<String, Error>>,
+ tx: Sender<MediaResult>,
) {
thread_pool.run(move || {
let fname = dw_media(baseu, &media, ContentType::Download, None);
@@ -48,7 +51,7 @@ pub fn get_media_list_async(
room_id: RoomId,
first_media_id: EventId,
prev_batch: Option<String>,
- tx: Sender<(Vec<Message>, String)>,
+ tx: Sender<MediaList>,
) {
thread_pool.run(move || {
let media_list = prev_batch
@@ -74,7 +77,7 @@ fn get_room_media_list(
room_id: &RoomId,
limit: u64,
prev_batch: String,
-) -> Result<(Vec<Message>, String), Error> {
+) -> Result<MediaList, Error> {
let params = GetMessagesEventsParams {
access_token,
from: prev_batch,
diff --git a/fractal-gtk/src/backend/user.rs b/fractal-gtk/src/backend/user.rs
index fb5d5ac9..3d5f3a75 100644
--- a/fractal-gtk/src/backend/user.rs
+++ b/fractal-gtk/src/backend/user.rs
@@ -68,6 +68,8 @@ use fractal_api::r0::ThreePIDCredentials;
use super::{dw_media, ContentType};
+pub type UserInfo = (String, String);
+
pub fn get_username(base: Url, uid: UserId) -> Result<Option<String>, Error> {
let request = get_display_name(base, &uid)?;
let response: GetDisplayNameResponse = HTTP_CLIENT.get_client()?.execute(request)?.json()?;
@@ -320,7 +322,7 @@ pub fn get_user_info_async(
user_info_cache: Arc<Mutex<CacheMap<UserId, (String, String)>>>,
baseu: Url,
uid: UserId,
- tx: Sender<(String, String)>,
+ tx: Sender<UserInfo>,
) {
if let Some(info) = user_info_cache.lock().unwrap().get(&uid).cloned() {
thread::spawn(move || {
diff --git a/fractal-gtk/src/widgets/image.rs b/fractal-gtk/src/widgets/image.rs
index 5dd5f185..0db294c1 100644
--- a/fractal-gtk/src/widgets/image.rs
+++ b/fractal-gtk/src/widgets/image.rs
@@ -260,10 +260,7 @@ impl Image {
pub fn load_async(&self, thread_pool: ThreadPool) {
if self.path.starts_with("mxc:") {
// asyn load
- let (tx, rx): (
- Sender<Result<String, Error>>,
- Receiver<Result<String, Error>>,
- ) = channel();
+ let (tx, rx): (Sender<media::MediaResult>, Receiver<media::MediaResult>) = channel();
let command = if self.thumb {
media::get_thumb_async
} else {
diff --git a/fractal-gtk/src/widgets/inline_player.rs b/fractal-gtk/src/widgets/inline_player.rs
index efa9d54d..ae016f95 100644
--- a/fractal-gtk/src/widgets/inline_player.rs
+++ b/fractal-gtk/src/widgets/inline_player.rs
@@ -503,10 +503,7 @@ impl<T: MediaPlayer + 'static> PlayerExt for T {
start_playing: bool,
) {
bx.set_opacity(0.3);
- let (tx, rx): (
- Sender<Result<String, Error>>,
- Receiver<Result<String, Error>>,
- ) = channel();
+ let (tx, rx): (Sender<media::MediaResult>, Receiver<media::MediaResult>) = channel();
media::get_media_async(thread_pool, server_url.clone(), media_url.to_string(), tx);
let local_path = player.get_local_path_access();
gtk::timeout_add(
diff --git a/fractal-gtk/src/widgets/media_viewer.rs b/fractal-gtk/src/widgets/media_viewer.rs
index 40178c63..6ea0b2eb 100644
--- a/fractal-gtk/src/widgets/media_viewer.rs
+++ b/fractal-gtk/src/widgets/media_viewer.rs
@@ -1023,10 +1023,7 @@ fn load_more_media(thread_pool: ThreadPool, data: Rc<RefCell<Data>>, builder: gt
let server_url = data.borrow().server_url.clone();
let access_token = data.borrow().access_token.clone();
- let (tx, rx): (
- Sender<(Vec<Message>, String)>,
- Receiver<(Vec<Message>, String)>,
- ) = channel();
+ let (tx, rx): (Sender<media::MediaList>, Receiver<media::MediaList>) = channel();
media::get_media_list_async(
thread_pool.clone(),
server_url,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]