Way to forward non associated function

Here is the situation:

struct MyDialog
{
inner: Dialog//3rdParty dialog I want to extend
}

impl MyDialog
{
/*here I need to define non-associated fn from Dialog, is there a way to forward it or I just need to copy paste?*/
/*signature of this fn:*/
pub fn around<V: IntoBoxedView>(view: V) -> Self ;
}

You can't forward it, because Self in these contexts is a different type. Rust is not an object-oriented language, and doesn't have inheritance, so there's no relationship between these types. You need to make the correct type:

pub fn around<V: IntoBoxedView>(view: V) -> Self { 
   Self(Dialog::around(view)) 
}

In Rust these patterns are called newtype and delegation. You should be able to find macros that help with the boilerplate round them, or just write your own.

1 Like

That's nice solution. Thanks