Restore operator T() on Field* and allow operator(*|->) on Ref/RefMut - #137
Restore operator T() on Field* and allow operator(*|->) on Ref/RefMut#137RaitoBezarius wants to merge 2 commits into
operator T() on Field* and allow operator(*|->) on Ref/RefMut#137Conversation
The primitive specializations of Ref/RefMut always provided operator*, but the per-type specializations generated for user-defined types did not, leaving no way to access the pointee of a Ref<UserType> other than calling zngur-declared methods on it. We emit operator*/operator-> for those specializations too, returning a reference aliasing the underlying Rust memory without taking ownership. Copying the value out works when the type is Copy, since its copy constructor performs the deep copy; non-Copy types keep their ownership discipline with respect to the deleted copy constructors on the C++ side. Signed-off-by: Raito Bezarius <raito@lix.systems>
The FieldOwned/FieldRef/FieldRefMut primary templates define a conversion to T, but the per-type explicit specializations generated for each user-defined type silently dropped it. Types with a specialization (e.g. Bool) therefore lost the conversion that primitive field types had. Only Copy types can support the conversion: it copies the value out of the parent object, which is impossible for non-Copy types whose copy constructor is deleted. The definition is emitted out-of-line near the end of the header because the specializations are generated before the type and Ref definitions it needs. Regression tests cover Bool, Copy structs and Copy generic instantiations (Option<&T>, Option<T: Copy>). Fixes hkalbasi#133. Signed-off-by: Raito Bezarius <raito@lix.systems>
|
Thanks for the PR! I think adding a general propose |
I will drop the implementations and rework it accordingly, thanks. |
Fixes #133.
Each commit presents its rationale.
TL;DR:
operator*andoperator->(const/non-const) forRef/RefMutoperator T()onFieldRef/FieldMut/FieldOwnedusingoperator*onRef/RefMut