Skip to content

Add support for C++ user-defined conversion operators.#1226

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_932645952
Open

Add support for C++ user-defined conversion operators.#1226
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_932645952

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Jun 16, 2026

Copy link
Copy Markdown

Add support for C++ user-defined conversion operators.

We map depending on the target type and pin/move characteristics:

  • Movable, locally-defined type (Record is Unpin and local to the crate):
    operator Dst() const => impl From<&Src> for Dst
  • Immovable, locally-defined type:
    operator Dst() const => impl CtorNew<&Src> for Dst
  • Foreign types, primitives, or reference returns:
    If the target type is a value:
    operator Dst() const => impl Into<Dst> for &Src
    If the target type is a reference:
  • operator const Dst&() const => impl Into<CRef<'_, Dst>> for &Src
  • operator Dst&() => impl Into<CMut<'_, Dst>> for &mut Src

const T() maps the receiver to &Src, T() maps the receiver to &mut Src.

@google-cla

google-cla Bot commented Jun 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@copybara-service copybara-service Bot force-pushed the test_932645952 branch 7 times, most recently from fa02925 to ee57314 Compare June 18, 2026 15:23
We map depending on the target type and pin/move characteristics:
- Movable, locally-defined type (Record is  Unpin  and local to the crate):
`operator Dst() const` => `impl From<&Src> for Dst`
- Immovable, locally-defined type:
`operator Dst() const` => `impl CtorNew<&Src> for Dst`
- Foreign types, primitives, or reference returns:
If the target type is a value:
`operator Dst() const` => `impl Into<Dst> for &Src`
If the target type is a reference:
- `operator const Dst&() const` => `impl Into<CRef<'_, Dst>> for &Src`
- `operator Dst&()` => `impl Into<CMut<'_, Dst>> for &mut Src`

`const T()` maps the receiver to `&Src`, `T()` maps the receiver to `&mut Src`.

PiperOrigin-RevId: 932645952
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.

0 participants