From fde1cc78a14cae75e4a01334b5aeef6abd282f30 Mon Sep 17 00:00:00 2001 From: tidely <43219534+tidely@users.noreply.github.com> Date: Tue, 29 Apr 2025 22:43:54 +0300 Subject: [PATCH] gpui: Relax AssetLogger trait bounds (#29450) Loosen trait bounds from `std::error::Error` to `std::fmt::Display`, since it's not required for the `log::error!` macro or any other bounds. Specify that `AssetLogger` specifically logs errors in its documentation. Use the `futures::TryFutureExt` trait extension to use `inspect_err` directly on a future. Release Notes: - N/A --- crates/gpui/src/asset_cache.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/gpui/src/asset_cache.rs b/crates/gpui/src/asset_cache.rs index 3c6dbd99da..9afbba8a0e 100644 --- a/crates/gpui/src/asset_cache.rs +++ b/crates/gpui/src/asset_cache.rs @@ -1,5 +1,5 @@ use crate::{App, SharedString, SharedUri}; -use futures::Future; +use futures::{Future, TryFutureExt}; use std::fmt::Debug; use std::hash::{Hash, Hasher}; @@ -51,14 +51,17 @@ pub trait Asset: 'static { ) -> impl Future + Send + 'static; } -/// An asset Loader that logs whatever passes through it +/// An asset Loader which logs the [`Err`] variant of a [`Result`] during loading pub enum AssetLogger { #[doc(hidden)] _Phantom(PhantomData, &'static dyn crate::seal::Sealed), } -impl>> Asset - for AssetLogger +impl Asset for AssetLogger +where + T: Asset>, + R: Clone + Send, + E: Clone + Send + std::fmt::Display, { type Source = T::Source; @@ -69,10 +72,7 @@ impl impl Future + Send + 'static { let load = T::load(source, cx); - async { - load.await - .inspect_err(|e| log::error!("Failed to load asset: {}", e)) - } + load.inspect_err(|e| log::error!("Failed to load asset: {}", e)) } }