this post was submitted on 21 Jul 2023
3 points (80.0% liked)
Rust
6005 readers
9 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Yes, obviously, but there are de-referincing/borrwowing/trait problem.
If you want to check the Trait: https://docs.rs/ratatui/latest/ratatui/widgets/trait.Widget.html
If you want to check what function do I need to run: https://docs.rs/ratatui/latest/ratatui/terminal/struct.Frame.html#method.render_widget
So the struct is something like
struct Panel<T: Widget> { data: T }
(tried also with Box, Rc, &mut T and BoxI need to implement a method for Panel which simply uses the function linked above. (so just asks for a Frame, the Rect type is generated by my other function)
That function takes ownership of the Widget, there's no borrowing here. Maybe that's the problem, that you're passing a reference instead of the actual object?
So, if you have a Panel containing the Widget, the function you're calling
render_widget
in has to takeself
, not&self
or&mut self
.Alternatively, you can use
data: Option<T>
in Panel, let the function take&mut self
and then useself.data.take()
to move it out of self.I checked the code and noticed that I wrote
&self
as the parameter 🤦🏻Now everything works. Thanks man
Showing the code and the errors compiler gives to you would help a bunch.
Seems like
data: T
ordata: &'a mut T
should work for you. Your function should be acceptingmut self
or&mut self
.