|
| 1 | +// Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | +// Exceptions. See /LICENSE for license information. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | + |
| 5 | +// Automatically @generated C++ bindings for the following Rust crate: |
| 6 | +// example_crate_golden |
| 7 | +// Features: supported, types |
| 8 | + |
| 9 | +// clang-format off |
| 10 | +#ifndef THIRD_PARTY_CRUBIT_EXAMPLES_RUST_ENUM_WITH_PAYLOAD_EXAMPLE_CRATE_GOLDEN |
| 11 | +#define THIRD_PARTY_CRUBIT_EXAMPLES_RUST_ENUM_WITH_PAYLOAD_EXAMPLE_CRATE_GOLDEN |
| 12 | + |
| 13 | +#pragma clang diagnostic push |
| 14 | +#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" |
| 15 | +#pragma clang diagnostic ignored "-Wunused-private-field" |
| 16 | +#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 17 | +#include "support/annotations_internal.h" |
| 18 | +#include "support/internal/slot.h" |
| 19 | + |
| 20 | +#include <array> |
| 21 | +#include <cstddef> |
| 22 | +#include <cstdint> |
| 23 | +#include <cstring> |
| 24 | +#include <type_traits> |
| 25 | +#include <utility> |
| 26 | + |
| 27 | +namespace example_crate { |
| 28 | + |
| 29 | +// Generated from: |
| 30 | +// examples/rust/enum_with_payload/example.rs;l=6 |
| 31 | +struct CRUBIT_INTERNAL_RUST_TYPE(":: example_crate_golden :: Color") alignas(1) |
| 32 | + [[clang::trivial_abi]] Color final { |
| 33 | + public: |
| 34 | + // `example_crate_golden::Color` doesn't implement the `Default` trait |
| 35 | + Color() = delete; |
| 36 | + |
| 37 | + // A completely transparent color (no payload) |
| 38 | + // |
| 39 | + // Generated from: |
| 40 | + // examples/rust/enum_with_payload/example.rs;l=8 |
| 41 | + static constexpr Color MakeTransparent(); |
| 42 | + |
| 43 | + // A grayscale value from 0 to 255 |
| 44 | + // |
| 45 | + // Generated from: |
| 46 | + // examples/rust/enum_with_payload/example.rs;l=10 |
| 47 | + static ::example_crate::Color MakeGrayscale(std::uint8_t __param_0); |
| 48 | + |
| 49 | + // Red, Green, and Blue values from 0 to 255 |
| 50 | + // |
| 51 | + // Generated from: |
| 52 | + // examples/rust/enum_with_payload/example.rs;l=12 |
| 53 | + static ::example_crate::Color MakeRgb(std::uint8_t __param_0, |
| 54 | + std::uint8_t __param_1, |
| 55 | + std::uint8_t __param_2); |
| 56 | + |
| 57 | + // No custom `Drop` impl and no custom "drop glue" required |
| 58 | + ~Color() = default; |
| 59 | + Color(Color&&) = default; |
| 60 | + ::example_crate::Color& operator=(Color&&) = default; |
| 61 | + |
| 62 | + // Rust types that are `Copy` get trivial, `default` C++ copy constructor and |
| 63 | + // assignment operator. |
| 64 | + Color(const Color&) = default; |
| 65 | + ::example_crate::Color& operator=(const Color&) = default; |
| 66 | + Color(::crubit::UnsafeRelocateTag, Color&& value) { |
| 67 | + std::memcpy(this, &value, sizeof(value)); |
| 68 | + } |
| 69 | + |
| 70 | + private: |
| 71 | + // Field type has been replaced with a blob of bytes: No support for bindings |
| 72 | + // of individual non-repr(C) `enum`s |
| 73 | + std::array<unsigned char, 4> __opaque_blob_of_bytes; |
| 74 | + |
| 75 | + private: |
| 76 | + struct PrivateBytesTag {}; |
| 77 | + constexpr Color(PrivateBytesTag, std::array<unsigned char, 4> bytes) |
| 78 | + : __opaque_blob_of_bytes(bytes) {} |
| 79 | + |
| 80 | + private: |
| 81 | + static void __crubit_field_offset_assertions(); |
| 82 | +}; |
| 83 | + |
| 84 | +static_assert( |
| 85 | + sizeof(Color) == 4, |
| 86 | + "Verify that ADT layout didn't change since this header got generated"); |
| 87 | +static_assert( |
| 88 | + alignof(Color) == 1, |
| 89 | + "Verify that ADT layout didn't change since this header got generated"); |
| 90 | + |
| 91 | +// `static` constructor |
| 92 | +inline constexpr Color Color::MakeTransparent() { |
| 93 | + return Color(PrivateBytesTag{}, {0, 0, 0, 0}); |
| 94 | +} |
| 95 | + |
| 96 | +namespace __crubit_internal { |
| 97 | +extern "C" void __crubit_thunk_Grayscale(std::uint8_t, |
| 98 | + ::example_crate::Color* __ret_ptr); |
| 99 | +} |
| 100 | +inline ::example_crate::Color Color::MakeGrayscale(std::uint8_t __param_0) { |
| 101 | + crubit::Slot<::example_crate::Color> __return_value_ret_val_holder; |
| 102 | + auto* __return_value_storage = __return_value_ret_val_holder.Get(); |
| 103 | + __crubit_internal::__crubit_thunk_Grayscale(__param_0, |
| 104 | + __return_value_storage); |
| 105 | + return std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); |
| 106 | +} |
| 107 | + |
| 108 | +namespace __crubit_internal { |
| 109 | +extern "C" void __crubit_thunk_Rgb(std::uint8_t, std::uint8_t, std::uint8_t, |
| 110 | + ::example_crate::Color* __ret_ptr); |
| 111 | +} |
| 112 | +inline ::example_crate::Color Color::MakeRgb(std::uint8_t __param_0, |
| 113 | + std::uint8_t __param_1, |
| 114 | + std::uint8_t __param_2) { |
| 115 | + crubit::Slot<::example_crate::Color> __return_value_ret_val_holder; |
| 116 | + auto* __return_value_storage = __return_value_ret_val_holder.Get(); |
| 117 | + __crubit_internal::__crubit_thunk_Rgb(__param_0, __param_1, __param_2, |
| 118 | + __return_value_storage); |
| 119 | + return std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); |
| 120 | +} |
| 121 | +static_assert(std::is_trivially_destructible_v<Color>); |
| 122 | +static_assert(std::is_trivially_move_constructible_v<::example_crate::Color>); |
| 123 | +static_assert(std::is_trivially_move_assignable_v<::example_crate::Color>); |
| 124 | +static_assert(std::is_trivially_copy_constructible_v<::example_crate::Color>); |
| 125 | +static_assert(std::is_trivially_copy_assignable_v<::example_crate::Color>); |
| 126 | +inline void Color::__crubit_field_offset_assertions() { |
| 127 | + static_assert(0 == offsetof(Color, __opaque_blob_of_bytes)); |
| 128 | +} |
| 129 | +} // namespace example_crate |
| 130 | + |
| 131 | +#pragma clang diagnostic pop |
| 132 | +#endif // THIRD_PARTY_CRUBIT_EXAMPLES_RUST_ENUM_WITH_PAYLOAD_EXAMPLE_CRATE_GOLDEN |
0 commit comments