Skip to content

Add Clone support to AnyMap via type-erased clone functions#752

Open
wdcui wants to merge 1 commit intomainfrom
wdcui/pr3b-anymap-clone
Open

Add Clone support to AnyMap via type-erased clone functions#752
wdcui wants to merge 1 commit intomainfrom
wdcui/pr3b-anymap-clone

Conversation

@wdcui
Copy link
Copy Markdown
Member

@wdcui wdcui commented Apr 7, 2026

Summary

  • Add Clone impl for AnyMap using type-erased clone function pointers (since Clone is not object-safe, Box<dyn Any + Clone> is invalid Rust).
  • Require Clone bound on all types stored in AnyMap (insert() and set_entry_metadata()/set_fd_metadata()).
  • Add #[derive(Clone)] to shim types stored as fd metadata: StdioStatusFlags, PipeStatusFlags, SocketOptions, SocketOFlags, SocketProxy.

Split from #743.

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.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

🤖 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 jaybosamiya-ms added the expmt:shadow-kiln Tag to quickly find the different PRs as part of the "shadow kiln" experiment. label Apr 11, 2026
Copy link
Copy Markdown
Member

@jaybosamiya-ms jaybosamiya-ms left a comment

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

expmt:shadow-kiln Tag to quickly find the different PRs as part of the "shadow kiln" experiment.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants