Skip to content

interpreter: Make the From<ModelRc> for Value implement set_row_data #8575

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

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

ogoffart
Copy link
Member

When converting a ModelRc to a Value, the resulting model did not implement set_row_data and therefore would not allow changing the model from the code.
By adding a TryFrom bound, we can make sure set_row_data is implemented.

This is technically a breaking change to add this bound, but most type that implement From for value also implement TryFrom

These conversion function were added in
20443ec for Slint 1.9

@ogoffart ogoffart requested a review from tronical May 30, 2025 09:47
When converting a ModelRc<T> to a Value, the resulting model did not
implement set_row_data and therefore would not allow changing the model
from the code.
By adding a `TryFrom` bound, we can make sure set_row_data is
implemented.

This is technically a breaking change to add this bound, but most type
that implement From for value also implement TryFrom<Value>

These conversion function were added in
20443ec for Slint 1.9
@ogoffart ogoffart force-pushed the olivier/interpreter branch from ba1f4d2 to cfd06d8 Compare May 30, 2025 09:51
}

fn as_any(&self) -> &dyn core::any::Any {
self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that forward to the inner model?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it.
This would allow something like

// foo is a ModelRc<Value> that was build from a ModelRc wrapping a VecModel<SharedString>
foo.as_any().downcast_ref::<VecModel<SharedString>>()

But then it gets harder to make the following work

let xxx : ModelRc<SharedString> = value.try_into().unwrap() 

as the m.as_any().downcast_ref::<crate::value_model::ValueMapModel<T>> wouldn't work anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the what I was thinking of (the first case).

For the second case, I'm not sure I understand. Who needs to perform the downcast to the wrapper model? Is the issue that you'd like to get a clone instead of a ref?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogoffart ogoffart merged commit f3bcf7a into master Jun 2, 2025
40 checks passed
@ogoffart ogoffart deleted the olivier/interpreter branch June 2, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants