-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xilem_core: return element in View::rebuild
#3
xilem_core: return element in View::rebuild
#3
Conversation
It is very frustrating that there's no way to represent normal reborrowing in the type system. I am however slightly surprised by this requirement - I would think that you be able to use I really don't like that this adds that required |
Indeed, having a generalized type/trait, that
Yep I'm also not a big fan of it, but I don't know how we get around it otherwise, while having access to the element after
Well, I started doing something similar as masonry with a Anyway, when we want to do something similar in masonry what I'm currently doing in For example, when after a rebuild of a child view, an implementor decides to And well for my concrete usecase currently, by having a modifier system, that reads attributes of the element after the child views have modified it. |
Is it at all possible for you to manually reborrow for this use case (e.g. either with the signature of the commented-out Without seeing the code which requires this, I'm extremely hesitant to add it - it makes the |
I mean I can get around it with a lot of ugly interior mutability via something like As already written on zulip: I think it's a question about whether we want to make the
Other than the added boilerplate in the signature (which will mostly be autogenerated by rust-analyzer)? We could also return |
xilem_core/src/views/memoize.rs
Outdated
element: <Self::Element as ViewElement>::Mut<'_>, | ||
) { | ||
element: <Self::Element as ViewElement>::Mut<'a>, | ||
) -> <Self::Element as ViewElement>::Mut<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can add a xilem_core::Mut
type alias, to remove the as ViewElement
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested it with the following which does work:
pub type Mut<'a, E> = <E as ViewElement>::Mut<'a>;
it resolves to something like when using rust-analyzer and using it in the trait:
) -> <Self::Element as ViewElement>::Mut<'a> { | |
) -> xilem_core::Mut<'a, Self::Element> { |
Should I add that type alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be good. I'd hope to remove the xilem_core::
as well by importing it.
If it were in a seperate PR, I'd just merge that very quickly; I'm still not completely sure I want this change, although now is the time to make it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's possible with the code-action to remove that xilem_core::
, and when it's in scope (use xilem_core::Mut
) it won't appear in the code-action to impl that View
trait.
I get that hesitation, but I do think it's worth it, since it's basically all autogenerated boilerplate (via rust-analyzer) and the lifetime is somewhat trivial, but it adds additional flexibility (also in the main xilem implementation) by being able to modify the element after descendent views have modified it, which I think is quite useful for modifier based implementations that rely on previous modifications (while not having &mut E
as ViewElement::Mut
type).
…iewElement::Mut` It's not possible to modify the element otherwise, after descendent `View`s have used the element in `View::rebuild`
7f4faff
to
62a7e05
Compare
Additionally to the type alias and rebase, I did some cleanup for all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts on code style and nits on documentation. But I think this direction is fine
Co-authored-by: Daniel McNab <[email protected]>
Co-authored-by: Daniel McNab <[email protected]>
Thanks for the review, I'll merge |
New tracy image: ![image](https://github.com/user-attachments/assets/94e54c89-8159-4dd4-a521-4a7122f64375) New log tracing file: <details><summary>An overview of the new logs</summary> <p> ``` 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}: masonry::passes::update: RootWidget received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}: masonry::passes::update: SizedBox received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}:Flex{id=linebender#6}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}:Flex{id=linebender#6}:Flex{id=#3}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}:Flex{id=linebender#6}:Flex{id=#3}:Prose{id=#1}: masonry::passes::update: Prose received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}:Flex{id=linebender#6}:Flex{id=#3}:Label{id=#2}: masonry::passes::update: Label received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}:Flex{id=linebender#6}:Flex{id=linebender#5}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#8}:SizedBox{id=linebender#7}:Flex{id=linebender#6}:Flex{id=linebender#5}:VariableLabel{id=#4}: masonry::passes::update: VariableLabel received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#10}: masonry::passes::update: Button received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#10}:Label{id=linebender#9}: masonry::passes::update: Label received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#12}: masonry::passes::update: Button received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#12}:Label{id=linebender#11}: masonry::passes::update: Label received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#14}: masonry::passes::update: Button received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#14}:Label{id=linebender#13}: masonry::passes::update: Label received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#16}: masonry::passes::update: Button received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Flex{id=linebender#17}:Button{id=linebender#16}:Label{id=linebender#15}: masonry::passes::update: Label received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}: masonry::passes::update: Portal received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}: masonry::passes::update: SizedBox received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}:Flex{id=linebender#23}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}:Flex{id=linebender#23}:Flex{id=linebender#20}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}:Flex{id=linebender#23}:Flex{id=linebender#20}:Prose{id=linebender#18}: masonry::passes::update: Prose received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}:Flex{id=linebender#23}:Flex{id=linebender#20}:Label{id=linebender#19}: masonry::passes::update: Label received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}:Flex{id=linebender#23}:Flex{id=linebender#22}: masonry::passes::update: Flex received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#24}:Flex{id=linebender#23}:Flex{id=linebender#22}:VariableLabel{id=linebender#21}: masonry::passes::update: VariableLabel received Update::WidgetAdded 14:37:40.365Z TRACE update_new_widgets:RootWidget{id=linebender#165}:Flex{id=linebender#164}:Portal{id=linebender#163}:Flex{id=linebender#160}:SizedBox{id=linebender#31}: masonry::passes::update: SizedBox received Update::WidgetAdded ``` </p> </details> This was originally an experiment into caching spans, but I determined that was non-viable due to the pass names.
So this resulted out of experimenting with a rewrite of
xilem_web
where I needed access to the element after wrapping views have usedView::rebuild
.It was not possible to access the element anymore because of the move of element type
ViewElement::Mut
, so this (unfortunately further complexification) made this possible again by returningViewElement::Mut
. I've tested all the examples, and they all are running as expected.Maybe this also helps with the reborrowing issue?