use std::{fmt, sync::Arc};
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct WindowKey(Arc<str>);
impl WindowKey {
pub const MAIN: &'static str = "main";
pub fn new(name: impl AsRef<str>) -> Self {
Self(Arc::from(name.as_ref()))
}
pub fn main() -> Self {
Self::new(Self::MAIN)
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl Default for WindowKey {
fn default() -> Self {
Self::main()
}
}
impl fmt::Debug for WindowKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "WindowKey({:?})", self.0)
}
}
impl fmt::Display for WindowKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl From<&str> for WindowKey {
fn from(name: &str) -> Self {
Self::new(name)
}
}
impl From<String> for WindowKey {
fn from(name: String) -> Self {
Self::new(name)
}
}
impl From<&WindowKey> for WindowKey {
fn from(key: &WindowKey) -> Self {
key.clone()
}
}