Skip to content
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

Explore inline dyn for less indirection #4

Open
kpreid opened this issue Dec 20, 2024 · 1 comment
Open

Explore inline dyn for less indirection #4

kpreid opened this issue Dec 20, 2024 · 1 comment
Labels

Comments

@kpreid
Copy link
Owner

kpreid commented Dec 20, 2024

Our use of Vec<Arc<dyn Listener>> and the fact that Listener implementations usually have Weaks mean that most listeners are stored and invoked with double indirection (or triple if you count the Vec). Can we use an inline-boxed-trait-object type (or dyn*, experimentally?) so as to avoid the double indirection? objectionable is a library that claims to provide an InlineBox type which does what we need for that, but I have not tried actually using it.

Another strategy would be a "Vec of unsized elements" container, of which there are a couple experimental ones to be found:

However, using this would come at the cost of some awkward API (until such time as CoerceUnsized is stable) and we could no longer have dyn Listen (because the concrete type would have to be passed generically all the way to the Notifier all the time).

@kpreid
Copy link
Owner Author

kpreid commented Dec 22, 2024

The current state of unstable dyn* is that Rc, Arc, Weak cannot be used in it, and changing that is not quite as simple as adding the necessary impls to alloc. Filed rust-lang/rust#134591 for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant