gtk-rs-core
gtk-rs-core copied to clipboard
Figure out how to handle custom "subclassing" traits
See https://github.com/gtk-rs/gtk4-rs/pull/500 for context
Currently for cairo:
You have a parent type cairo::Surface and other sub-types like cairo::ImageSurface. If a function takes a cairo::Surface and you have a cairo::ImageSurface, you pass it as such some_func(&*image_surface) that's because there's a impl Deref for cairo::WhateverSurface with a target = cairo::Surface
for gtk4-rs, we use AsRef in those functions, we can then just call some_func(&some_render_node) , we should probably decide on something and use it across the crates.
I would vote for AsRef as it's kind of similar to IsA in terms of "syntax" and it's less magical than a Deref implementation :)
For single inheritance without interfaces it makes sense to use Deref IMHO, but if you feel strong about it you can also do AsRef<Parent> and impl<T: AsRef<Parent>> ExtTrait for T { ... } instead. It's just more boilerplate.
@bilelmoussaoui What should we do about this?
I guess similar to have we did for fundamental types, going with impl AsRef T.
You do that?
Sure, I will update gtk4-rs per the changes in #783 first