Skip to content

Allow usage of ?Sized types in register_shared - #2

Open
nicopap wants to merge 1 commit into
mineichen:mainfrom
npapale:fat-arc-ptr
Open

Allow usage of ?Sized types in register_shared#2
nicopap wants to merge 1 commit into
mineichen:mainfrom
npapale:fat-arc-ptr

Conversation

@nicopap

@nicopap nicopap commented Jul 6, 2026

Copy link
Copy Markdown

No description provided.

@nicopap

nicopap commented Jul 7, 2026

Copy link
Copy Markdown
Author

Hmm. I think I've a workaround for what I thought I needed this for. Instead of storing directly Arc<T> for your non-sized T, store Arc<Box<T>>.

To make it short, register_shared accepts a Arc<T> as return type of the factory. But T: Sized, which can be problematic if we want to return T = dyn Trait.

The reason T: Sized is that *const T for T: !Sized is a fat pointer, and rust doesn't expose ways to manipulate metadata in fat pointers, generally it's impossible to just store a *const T for unsized type and get back a &T.

Generally, because with the hack I introduce, it's technically possible.

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.

1 participant