feat: Update to latest iced

This commit is contained in:
uttarayan21
2025-11-18 23:54:27 +05:30
parent a6ef6ba9c0
commit 3222c26bb6
15 changed files with 1231 additions and 4918 deletions

View File

@@ -0,0 +1,68 @@
use std::{borrow::Cow, sync::Arc};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SharedString(ArcCow<'static, str>);
impl From<String> for SharedString {
fn from(s: String) -> Self {
SharedString(ArcCow::Owned(Arc::from(s)))
}
}
impl<'a> iced::advanced::text::IntoFragment<'a> for SharedString {
fn into_fragment(self) -> Cow<'a, str> {
match self.0 {
ArcCow::Borrowed(b) => Cow::Borrowed(b),
ArcCow::Owned(o) => Cow::Owned(o.as_ref().to_string()),
}
}
}
impl<'a> iced::advanced::text::IntoFragment<'a> for &SharedString {
fn into_fragment(self) -> Cow<'a, str> {
match &self.0 {
ArcCow::Borrowed(b) => Cow::Borrowed(b),
ArcCow::Owned(o) => Cow::Owned(o.as_ref().to_string()),
}
}
}
impl From<&'static str> for SharedString {
fn from(s: &'static str) -> Self {
SharedString(ArcCow::Borrowed(s))
}
}
impl AsRef<str> for SharedString {
fn as_ref(&self) -> &str {
match &self.0 {
ArcCow::Borrowed(b) => b,
ArcCow::Owned(o) => o.as_ref(),
}
}
}
impl std::ops::Deref for SharedString {
type Target = str;
fn deref(&self) -> &Self::Target {
self.as_ref()
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum ArcCow<'a, T: ?Sized> {
Borrowed(&'a T),
Owned(Arc<T>),
}
impl<'a, T> Clone for ArcCow<'a, T>
where
T: ?Sized,
{
fn clone(&self) -> Self {
match self {
ArcCow::Borrowed(b) => ArcCow::Borrowed(b),
ArcCow::Owned(o) => ArcCow::Owned(Arc::clone(o)),
}
}
}