[Solved] How can i call a method in another struct/trait


#1

Hi i try to call a method in another trait.
Maybe is std::sync::Arc or std::cell::RefCell the answer?
I have at the moment no idea how i can solve this problem.

I created a example with my problem:
https://play.rust-lang.org/?gist=78f7b3a4b4b5549683cb852d20235520&version=stable&mode=debug&edition=2015

thanks :slight_smile:


#2

Here’s a quick fix:

https://play.rust-lang.org/?gist=fe05aaa474995298e09152f23a34e68b&version=stable&mode=debug&edition=2015

(edit: sorry, wrong link when I posted first, it’s now fixed).


#3

Unless you have a specific reason to want a trait object in draw_line_algorithm, you should change it to be generic:

fn draw_line_algorithm<D: Draw + ?Sized>(drawer: &mut D) { ... }

#4

Perfect! Thanks, this is exactly what i needed. :grinning: