Skip to main content

gpui/
shared_uri.rs

1use derive_more::{Deref, DerefMut};
2
3use crate::SharedString;
4
5/// A URI held in a [`SharedString`], so cloning the handle does not copy its text.
6///
7/// The text is not validated. Converting a `SharedUri` into an [`ImageSource`](crate::ImageSource)
8/// always treats it as a URL, bypassing the scheme check applied to a plain `&str`. See
9/// [`ImageSource`](crate::ImageSource) for the corresponding string conversions.
10#[derive(Deref, DerefMut, Default, PartialEq, Eq, Hash, Clone)]
11pub struct SharedUri(SharedString);
12
13impl std::fmt::Debug for SharedUri {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        self.0.fmt(f)
16    }
17}
18
19impl std::fmt::Display for SharedUri {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        write!(f, "{}", self.0.as_ref())
22    }
23}
24
25impl<T: Into<SharedString>> From<T> for SharedUri {
26    fn from(value: T) -> Self {
27        Self(value.into())
28    }
29}