Checkpoint
This commit is contained in:
parent
46451f2a8b
commit
6d4dd0e7a4
11 changed files with 151 additions and 9 deletions
|
@ -1,53 +0,0 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
pub enum ArcCow<'a, T: ?Sized> {
|
||||
Borrowed(&'a T),
|
||||
Owned(Arc<T>),
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized> Clone for ArcCow<'a, T> {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
Self::Borrowed(borrowed) => Self::Borrowed(borrowed),
|
||||
Self::Owned(owned) => Self::Owned(owned.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized> From<&'a T> for ArcCow<'a, T> {
|
||||
fn from(s: &'a T) -> Self {
|
||||
Self::Borrowed(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Arc<T>> for ArcCow<'_, T> {
|
||||
fn from(s: Arc<T>) -> Self {
|
||||
Self::Owned(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for ArcCow<'_, str> {
|
||||
fn from(value: String) -> Self {
|
||||
Self::Owned(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> std::ops::Deref for ArcCow<'_, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
ArcCow::Borrowed(s) => s,
|
||||
ArcCow::Owned(s) => s.as_ref(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ?Sized> AsRef<T> for ArcCow<'_, T> {
|
||||
fn as_ref(&self) -> &T {
|
||||
match self {
|
||||
ArcCow::Borrowed(borrowed) => borrowed,
|
||||
ArcCow::Owned(owned) => owned.as_ref(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,12 +2,12 @@ use crate::{
|
|||
element::{Element, IntoElement, Layout},
|
||||
layout_context::LayoutContext,
|
||||
paint_context::PaintContext,
|
||||
ArcCow,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use gpui::{geometry::Size, text_layout::LineLayout, LayoutId};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
use util::arc_cow::ArcCow;
|
||||
|
||||
impl<V: 'static, S: Into<ArcCow<'static, str>>> IntoElement<V> for S {
|
||||
type Element = Text;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
pub mod adapter;
|
||||
mod arc_cow;
|
||||
pub mod color;
|
||||
pub mod element;
|
||||
pub mod elements;
|
||||
|
@ -9,7 +8,6 @@ pub mod paint_context;
|
|||
pub mod style;
|
||||
pub mod view;
|
||||
|
||||
pub use arc_cow::ArcCow;
|
||||
pub use color::*;
|
||||
pub use element::{AnyElement, Element, IntoElement, Layout, ParentElement};
|
||||
pub use geometry::{
|
||||
|
@ -21,4 +19,5 @@ pub use gpui2_macros::{Element, *};
|
|||
pub use interactive::*;
|
||||
pub use layout_context::LayoutContext;
|
||||
pub use platform::{Platform, WindowBounds, WindowOptions};
|
||||
pub use util::arc_cow::ArcCow;
|
||||
pub use view::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue