The method defined by the attribute can take the implementation of the structure as a parameter using a keyword self. But I cannot figure out how to return an instance of the implementing structure. For instance:
trait Construct {
fn use_self(self) -> uint;
fn make_self(n: uint) -> self;
}
use_selfexcellent and compiles, but make_selfdoes not compile. Is there a way for the trait method to return an instance of the implementing structure, such as a constructor or initializer?
source
share