fidl_next_codec/wire/
empty_struct.rs

1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use core::mem::MaybeUninit;
6
7use crate::Wire;
8
9/// An empty struct's wire representation. C/C++ memory layout rules (and hence
10/// FIDL wire rules) require every object to have a unique address so we have to
11/// make a single, tiny type for empty structs.
12#[repr(u8)]
13#[derive(Clone, Copy)]
14pub enum WireEmptyStructPlaceholder {
15    /// Empty structs are represented as a single 0u8.
16    Zero = 0,
17}
18
19unsafe impl Wire for WireEmptyStructPlaceholder {
20    type Decoded<'de> = Self;
21
22    #[inline]
23    fn zero_padding(_: &mut MaybeUninit<Self>) {}
24}
25impl core::fmt::Debug for WireEmptyStructPlaceholder {
26    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27        write!(f, "(empty)")
28    }
29}