Looking for feedback on my implementation of thin trait objects

Howdy folks!

I've been working on my own implementation of the thin_trait_object crate, as I was unhappy with its API and wanted something 'nicer' to work with in my own projects. I also found its inner workings rather difficult to understand, and have tried to make mine a bit more readable.

Now that I feel it's in a minimum viable state, I'd love to get some feedback! Specifically, do you think I've improved on the API and what might I do to improve code readability? But most importantly, can you spot any potential unsoundness?

The source code can be found here:

I didn't look at the procedural macro, but if the code in template_impl resembles accurately how macro-generated code looks, I think there's a mistake in the shim function for trait methods with &self receivers. for example:

the trait method for foo() uses a shared reference &self as the receiver:

this means there can be multple references to the object when self.foo() is called, it would be a violation of the aliasing rule to create the exclusive reference bundle: &mut Bundle<T> and &mut bundle.val: &mut T in this function:

however, this might just be an oversight in this sample "template", and the macro is correct.

other than this issue, the design looks solid to me.

1 Like

Thanks for having a look!

I've confirmed this issue is also present in the proc macro. I'll work on a fix for it now.

1 Like

I think it should be fixed now!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.