Make AnyInvocable remember more information
Add an extra variant to FunctionToCall: `relocate_from_to_and_query_rust`. It is identical to "relocate_from_to" for C++ managers, but instructs Rust managers to perform a special operation that can be detected by the caller.
PiperOrigin-RevId: 837257408
Change-Id: Idc270af2716252612a77a26b1b3cf83778aaa20d
diff --git a/absl/functional/internal/any_invocable.h b/absl/functional/internal/any_invocable.h
index a696fdd..597c210 100644
--- a/absl/functional/internal/any_invocable.h
+++ b/absl/functional/internal/any_invocable.h
@@ -159,10 +159,18 @@
// A discriminator when calling the "manager" function that describes operation
// type-erased operation should be invoked.
//
+// "dispose" specifies that the manager should perform a destroy.
+//
// "relocate_from_to" specifies that the manager should perform a move.
//
-// "dispose" specifies that the manager should perform a destroy.
-enum class FunctionToCall : bool { relocate_from_to, dispose };
+// "relocate_from_to_and_query_rust" is identical to "relocate_from_to" for C++
+// managers, but instructs Rust managers to perform a special operation that
+// can be detected by the caller.
+enum class FunctionToCall : unsigned char {
+ dispose,
+ relocate_from_to,
+ relocate_from_to_and_query_rust,
+};
// The portion of `AnyInvocable` state that contains either a pointer to the
// target object or the object itself in local storage
@@ -243,6 +251,7 @@
switch (operation) {
case FunctionToCall::relocate_from_to:
+ case FunctionToCall::relocate_from_to_and_query_rust:
// NOTE: Requires that the left-hand operand is already empty.
::new (static_cast<void*>(&to->storage)) T(std::move(from_object));
ABSL_FALLTHROUGH_INTENDED;
@@ -277,6 +286,7 @@
TypeErasedState* const to) noexcept {
switch (operation) {
case FunctionToCall::relocate_from_to:
+ case FunctionToCall::relocate_from_to_and_query_rust:
// NOTE: Requires that the left-hand operand is already empty.
to->remote = from->remote;
return;
@@ -303,6 +313,7 @@
switch (operation) {
case FunctionToCall::relocate_from_to:
+ case FunctionToCall::relocate_from_to_and_query_rust:
// NOTE: Requires that the left-hand operand is already empty.
to->remote.target = from->remote.target;
return;