gpui: Add SharedUrl
type (#3975)
This PR adds a `SharedUrl` type to GPUI. It's just like a `SharedString`, but for denoting that the contained value is a URL. Mainlined from @nathansobo's GPUI blog post: https://github.com/zed-industries/zed/pull/3968/files#diff-7ee75937e2daf7dd53f71b17698d8bd6d46993d06928d411781b9bd739b5f231R9-R12 Release Notes: - N/A
This commit is contained in:
parent
fa53353c57
commit
f0ef63bfa0
7 changed files with 48 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::{ImageData, ImageId, SharedString};
|
||||
use crate::{ImageData, ImageId, SharedUrl};
|
||||
use collections::HashMap;
|
||||
use futures::{
|
||||
future::{BoxFuture, Shared},
|
||||
|
@ -44,7 +44,7 @@ impl From<ImageError> for Error {
|
|||
|
||||
pub struct ImageCache {
|
||||
client: Arc<dyn HttpClient>,
|
||||
images: Arc<Mutex<HashMap<SharedString, FetchImageFuture>>>,
|
||||
images: Arc<Mutex<HashMap<SharedUrl, FetchImageFuture>>>,
|
||||
}
|
||||
|
||||
type FetchImageFuture = Shared<BoxFuture<'static, Result<Arc<ImageData>, Error>>>;
|
||||
|
@ -59,7 +59,7 @@ impl ImageCache {
|
|||
|
||||
pub fn get(
|
||||
&self,
|
||||
uri: impl Into<SharedString>,
|
||||
uri: impl Into<SharedUrl>,
|
||||
) -> Shared<BoxFuture<'static, Result<Arc<ImageData>, Error>>> {
|
||||
let uri = uri.into();
|
||||
let mut images = self.images.lock();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue