1mod app;
2mod color;
3mod element;
4mod elements;
5mod executor;
6mod geometry;
7mod platform;
8mod renderer;
9mod scene;
10mod style;
11mod style_helpers;
12mod styled;
13mod taffy;
14mod text_system;
15mod util;
16mod window;
17
18use anyhow::Result;
19pub use app::*;
20pub use color::*;
21pub use element::*;
22pub use elements::*;
23pub use executor::*;
24pub use geometry::*;
25pub use platform::*;
26pub use refineable::*;
27pub use scene::*;
28pub use serde;
29pub use serde_json;
30pub use smallvec;
31pub use smol::Timer;
32use std::ops::{Deref, DerefMut};
33pub use style::*;
34pub use style_helpers::*;
35pub use styled::*;
36use taffy::TaffyLayoutEngine;
37pub use taffy::{AvailableSpace, LayoutId};
38pub use text_system::*;
39pub use util::arc_cow::ArcCow;
40pub use window::*;
41
42pub trait Context {
43 type EntityContext<'a, 'w, T: 'static>;
44
45 fn entity<T: 'static>(
46 &mut self,
47 build_entity: impl FnOnce(&mut Self::EntityContext<'_, '_, T>) -> T,
48 ) -> Handle<T>;
49
50 fn update_entity<T: 'static, R>(
51 &mut self,
52 handle: &Handle<T>,
53 update: impl FnOnce(&mut T, &mut Self::EntityContext<'_, '_, T>) -> R,
54 ) -> R;
55}
56
57#[derive(Clone, Eq, PartialEq)]
58pub struct SharedString(ArcCow<'static, str>);
59
60impl Default for SharedString {
61 fn default() -> Self {
62 Self(ArcCow::Owned("".into()))
63 }
64}
65
66impl AsRef<str> for SharedString {
67 fn as_ref(&self) -> &str {
68 &self.0
69 }
70}
71
72impl std::fmt::Debug for SharedString {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 self.0.fmt(f)
75 }
76}
77
78impl<T: Into<ArcCow<'static, str>>> From<T> for SharedString {
79 fn from(value: T) -> Self {
80 Self(value.into())
81 }
82}
83
84pub enum Reference<'a, T> {
85 Immutable(&'a T),
86 Mutable(&'a mut T),
87}
88
89impl<'a, T> Deref for Reference<'a, T> {
90 type Target = T;
91
92 fn deref(&self) -> &Self::Target {
93 match self {
94 Reference::Immutable(target) => target,
95 Reference::Mutable(target) => target,
96 }
97 }
98}
99
100impl<'a, T> DerefMut for Reference<'a, T> {
101 fn deref_mut(&mut self) -> &mut Self::Target {
102 match self {
103 Reference::Immutable(_) => {
104 panic!("cannot mutably deref an immutable reference. this is a bug in GPUI.");
105 }
106 Reference::Mutable(target) => target,
107 }
108 }
109}