Skip to content

Add Swappable trait - #689

Merged
nunoplopes merged 21 commits into
Cpp2Rust:masterfrom
lucic71:swappable
Dec 1, 2026
Merged

nunoplopes merged 21 commits into
Cpp2Rust:masterfrom
lucic71:swappable

Conversation

@lucic71

@lucic71 lucic71 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Depends on #688

Add the swappable trait and delete the cpp_swap macro. swap_by_move is a new libcc2rs function with the necessary traits:

pub fn swap_by_move<T>(this: &Ptr<T>, other: Ptr<T>)
where
  T: MoveConstructible + MoveAssignable + Destructible + ZeroInitialization

The standard explicitely requires MoveConstructible and MoveAssignable, and implicitly requires Destructible. ZeroInitialization is an artefact of refcount which needs storage to build objects into it. ZeroInitialization has no side-effects so it's ok to have the trait attached.


I also had to change Destructible to be implemented by records with empty destruction, otherwise records with empty Destructible could not call swap_by_move.

@nunoplopes
nunoplopes merged commit cc5f8a2 into Cpp2Rust:master Dec 1, 2026
9 checks passed
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.

2 participants