Skip to content

Add weak/strong global handles#10924

Open
LeonMatthes wants to merge 1 commit intomasterfrom
feature/weak-strong-globals
Open

Add weak/strong global handles#10924
LeonMatthes wants to merge 1 commit intomasterfrom
feature/weak-strong-globals

Conversation

@LeonMatthes
Copy link
Collaborator

No description provided.

The idea to make it easier and more convenient to pass a reference
to a Slint global instance into a Rust closure / lambda.

Fixes #9389
@LeonMatthes LeonMatthes marked this pull request as ready for review March 6, 2026 13:49
@LeonMatthes LeonMatthes requested review from ogoffart and tronical and removed request for ogoffart March 6, 2026 13:50
Copy link
Member

@tronical tronical left a comment

Choose a reason for hiding this comment

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

Looks good overall. I'm mostly concerned about the documentation, as you can see in the comments ;)

/// The `StrongHandle` trait is implemented for each global.
/// It marks this component as holding a strong reference to the Slint element tree
/// and allows using this component with a Weak reference.
impl StrongHandle for SampleGlobal<'static> {
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, why is it important to show that this trait is implemented? Users should never call a function on the trait, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is important because that is what enables it to be stored in a Weak and it shows up as the first part of the Weak documentation. If this trait was hidden or not documented it would be odd that you cannot easily identify what can be put in a Weak and what can't.

image

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I can phrase this differently: If we document this trait, it needs to be documented in a way that conveys to the users what they can do with it, how it relates to the rest of the API.

It is important because that is what enables it to be stored in a Weak

Why is this important to me as a user of the API? What does "enabling" me for me as a user?

(I'm asking because whatever the answer is, it would most likely belong into the docs :-)

and it shows up as the first part of the Weak documentation.

I think it's not uncommon to have internal traits be visible in bounds, etc. but keep the hidden.

@LeonMatthes LeonMatthes force-pushed the feature/weak-strong-globals branch from 1bc64c0 to ec0965f Compare March 6, 2026 15:01
@LeonMatthes LeonMatthes requested a review from tronical March 6, 2026 15:01
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.

3 participants