this post was submitted on 21 Jul 2023
3 points (80.0% liked)

Rust

6113 readers
7 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
 

crosspostato da: https://lemmy.world/post/1916287

Hi everybody, I'm new to Rust.

So, I have a struct Panel which contains a data widget which implements the trait Widget I have to implement a function for Panel that uses another function that requires a type that implements Widget.

I tried Box<T>, Rc<T>, Box<dyn Widget, &T, but nothing, always compiler errors.

How can I fix this?

you are viewing a single comment's thread
view the rest of the comments
[–] akash_rawal 1 points 1 year ago

Seems like data: T or data: &'a mut T should work for you. Your function should be accepting mut self or &mut self.