Add Clone support to AnyMap via type-erased clone functions#752
Open
Add Clone support to AnyMap via type-erased clone functions#752
Conversation
Clone is not object-safe, so Box<dyn Any + Send + Sync + Clone> is not valid Rust. Instead, store a type-erased clone function pointer alongside each value that knows the concrete type and can clone through the trait object. This requires all types stored in AnyMap to implement Clone. Update the Clone bound on insert() and set_entry_metadata()/set_fd_metadata() in fd/mod.rs, and add #[derive(Clone)] to shim types that are stored as fd metadata: StdioStatusFlags, PipeStatusFlags, SocketOptions, SocketOFlags, SocketProxy.
|
🤖 SemverChecks 🤖 No breaking API changes detected Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered. |
jaybosamiya-ms
requested changes
Apr 13, 2026
Member
jaybosamiya-ms
left a comment
There was a problem hiding this comment.
The design suggested in this PR feels somewhat brittle to me. Thus, I've implemented a stricter variant in #771 that fully supersedes this PR. No changes requested here, just keeping it open so we have a better understanding of the whole experiment at once, rather than missing this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cloneimpl forAnyMapusing type-erased clone function pointers (sinceCloneis not object-safe,Box<dyn Any + Clone>is invalid Rust).Clonebound on all types stored inAnyMap(insert()andset_entry_metadata()/set_fd_metadata()).#[derive(Clone)]to shim types stored as fd metadata:StdioStatusFlags,PipeStatusFlags,SocketOptions,SocketOFlags,SocketProxy.Split from #743.