Skip to content

Conversation

@wyatt-herkamp
Copy link

@wyatt-herkamp wyatt-herkamp commented Oct 31, 2025

Which issue does this PR close?

Closes #525

Rationale for this change

Allows you to put Arc<T> into something like struct ObjectStoreWrapper<T: ObjectStore>(T)

What changes are included in this PR?

Implementing ObjectStore for Arc<T> and Box<T>

Are there any user-facing changes?

No and this should not break anything. Just expand the flexibility of the ObjectStore Trait.

@kylebarron
Copy link
Member

kylebarron commented Oct 31, 2025

I think the reasoning for Arc<T> makes sense. Arrow does that too.

The reasoning for Box<T> is less clear to me because ObjectStore isn't mutable

@wyatt-herkamp
Copy link
Author

wyatt-herkamp commented Oct 31, 2025

The reasoning for Box is less clear to me because ObjectStore isn't mutable

I did Box because it is pretty common for traits to implement Box<T>, and Box<dyn ObjectStore> was already implemented.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @wyatt-herkamp

src/lib.rs Outdated
as_ref_impl!(Arc<dyn ObjectStore>);
as_ref_impl!(Box<dyn ObjectStore>);

macro_rules! as_ref_generic_impl {
Copy link
Contributor

Choose a reason for hiding this comment

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

this macro looks very similar to as_ref_impl -- if we implement for all Arc<T>/Box<T> could we remove the explicit implementations for Arc<dyn ..> and Box<dyn ..> 🤔

Copy link
Author

Choose a reason for hiding this comment

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

We could, but I think it would be a breaking change. I can merge the macros together by adding a second brand on the as_ref_impl macro if you would like?

Copy link
Member

Choose a reason for hiding this comment

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

It would be a breaking change?

Copy link
Author

Choose a reason for hiding this comment

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

Well, if we remove the implementation for Arc<dyn ...> and Box<dyn ...>, anyone who uses those implementations might have a problem.

Merging the macros isn't breaking. But removing those existing implementations might cause issues

Copy link
Member

Choose a reason for hiding this comment

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

My understanding of

if we implement for all Arc<T>/Box<T>

was that dyn ObjectStore already implemented T, so if you implement impl<T: ObjectStore> ObjectStore for Arc<T>, then maybe that already covers Arc<dyn ObjectStore>?

Copy link
Author

Choose a reason for hiding this comment

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

Oh I just remembered something!

Rust automatically adds the Sized bound. We need to add + ?Sized

Copy link
Author

Choose a reason for hiding this comment

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

Ok T: ObjectStore doesn't cover Box<dyn ObjectStore> but T: ObjectStore + ?Sized does.
The same applies to Arc<T>

@wyatt-herkamp wyatt-herkamp force-pushed the wyatt/as_ref_generic_impl branch from bd2a791 to da1add7 Compare November 9, 2025 16:42
@wyatt-herkamp
Copy link
Author

Rebased after the addition of ObjectStoreExt trait

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.

Implement ObjectStore for Arc<T> and Box<T>

3 participants