Rename SharedUrl
to SharedUri
(#7084)
This PR renames `SharedUrl` to `SharedUri` to better reflect its intent. I'm still not entirely happy with this naming, as the file paths that we can store in here are not _really_ URIs, as they are lacking a protocol. I want to explore changing `SharedUri` / `SharedUrl` back to alway storing a URL and treat local filepaths differently, as it seems we're conflating two different concerns under the same umbrella, at the moment. Release Notes: - N/A
This commit is contained in:
parent
d18c0d9df0
commit
6c7893db35
14 changed files with 66 additions and 66 deletions
65
crates/gpui/src/shared_uri.rs
Normal file
65
crates/gpui/src/shared_uri.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crate::SharedString;
|
||||
|
||||
/// A URI stored in a [`SharedString`].
|
||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub enum SharedUri {
|
||||
/// A path to a local file.
|
||||
File(SharedString),
|
||||
/// A URL to a remote resource.
|
||||
Network(SharedString),
|
||||
}
|
||||
|
||||
impl SharedUri {
|
||||
/// Creates a [`SharedUri`] pointing to a local file.
|
||||
pub fn file<S: Into<SharedString>>(s: S) -> Self {
|
||||
Self::File(s.into())
|
||||
}
|
||||
|
||||
/// Creates a [`SharedUri`] pointing to a remote resource.
|
||||
pub fn network<S: Into<SharedString>>(s: S) -> Self {
|
||||
Self::Network(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SharedUri {
|
||||
fn default() -> Self {
|
||||
Self::Network(SharedString::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for SharedUri {
|
||||
type Target = SharedString;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
Self::File(s) => s,
|
||||
Self::Network(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for SharedUri {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
match self {
|
||||
Self::File(s) => s,
|
||||
Self::Network(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for SharedUri {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::File(s) => write!(f, "File({:?})", s),
|
||||
Self::Network(s) => write!(f, "Network({:?})", s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SharedUri {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.as_ref())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue