slint-ui / pin-weak

Small wrapper around an equivalent of Pin<Weak<T>>
MIT License
7 stars 3 forks source link

PinWeak unsized coercion #2

Open ennis opened 3 weeks ago

ennis commented 3 weeks ago

Currently this fails to compile:

fn test_coerce() {
     let _weak : PinWeak<dyn core::any::Any> = PinWeak::<()>::default();
}

whereas the std::rc::Weak version compiles (playground link)

I'm not sure if it's possible without CoerceUnsized which is not stabilized.

ogoffart commented 3 weeks ago

Right, there is currently no stable way to do that. https://rust-lang.github.io/rfcs/3621-derive-smart-pointer.html might be stabilized at some point and then we'd be able to do it.

In the mean time you need to coerce the Rc: Something like: weak.upgrade().map_or(PinWeak<dyn core::any::Any>::default(), |x| PinWeak::<dyn core::any::Any>::downgrade(x))