diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index b2900a84c..021701657 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -218,93 +218,6 @@ pub trait Component: re_exports::HasStaticVTable { fn run(self: core::pin::Pin<&Self>); } -/// Holds a strong reference to a component created from a .60 file. -/// -/// The SixtyFPS compiler will generate component structure. The T type parameter -/// is one of these structure. In order to create a ComponentHandle, you would -/// use the `T::new()` function, which returns a `ComponentHandle`. -/// -/// Internally, this is like a Rc pointer. -/// You can get a weak pointer out of it using the `as_weak` function. -pub struct ComponentHandle { - inner: vtable::VRc, -} - -impl Clone for ComponentHandle { - fn clone(&self) -> Self { - Self { inner: self.inner.clone() } - } -} - -impl core::ops::Deref for ComponentHandle { - type Target = T; - fn deref(&self) -> &Self::Target { - &*self.inner - } -} - -impl From> for ComponentHandle { - fn from(value: vtable::VRc) -> Self { - Self { inner: value } - } -} - -impl From> for vtable::VRc { - fn from(value: ComponentHandle) -> Self { - value.inner - } -} - -impl ComponentHandle { - /// Create a weak handle to this handle. - pub fn as_weak(&self) -> ComponentWeakHandle { - ComponentWeakHandle { inner: vtable::VRc::downgrade(&self.inner) } - } - /// Returns a pinned reference to this component. - pub fn as_ref(&self) -> core::pin::Pin<&T> { - vtable::VRc::as_pin_ref(&self.inner) - } - - /// Show this component and run the event loop - pub fn run(self) { - self.as_ref().run() - } -} - -impl ComponentHandle { - /// Temporary addition until this class is gone. - pub fn as_rc(&self) -> vtable::VRc { - self.inner.clone() - } -} - -/// A weak handle to a component created from a .60 file. -/// -/// One create a ComponentWeakHandle using the [`ComponentHandle::as_weak`] function, and one -/// can get back the original ComponentHandle using the [`Self::upgrade`] function. -pub struct ComponentWeakHandle { - inner: vtable::VWeak, -} - -impl Clone for ComponentWeakHandle { - fn clone(&self) -> Self { - Self { inner: self.inner.clone() } - } -} - -impl Default for ComponentWeakHandle { - fn default() -> Self { - Self { inner: Default::default() } - } -} - -impl ComponentWeakHandle { - /// Convert this weak pointer back to an actual - pub fn upgrade(&self) -> Option> { - self.inner.upgrade().map(|inner| ComponentHandle { inner }) - } -} - /// This trait describes the conversion of a strongly referenced SixtyFPS component, /// held by a [vtable::VRc] into a weak reference. pub trait IntoWeak { diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index b7bed036a..cb7deaa80 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -777,7 +777,7 @@ fn generate_component( let self_weak = if !component.is_global() { Some(quote!(self_weak)) } else { None }; let self_weak = self_weak.into_iter().collect::>(); let component_handle = if !component.is_global() { - quote!(sixtyfps::ComponentHandle) + quote!(vtable::VRc) } else { quote!(::core::pin::Pin<::std::rc::Rc>) }; @@ -806,7 +806,7 @@ fn generate_component( impl #public_struct { pub fn new(#(parent: sixtyfps::re_exports::VWeak::)* #window_parent_param) -> Self { - Self(#component_id::new(#parent_name #window_parent_name).as_rc()) + Self(#component_id::new(#parent_name #window_parent_name)) } #(#public_property_and_signal_accessors)*