fidl_next_codec/
util.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
5//! Helper types for encoding and decoding.
6
7use core::hint::unreachable_unchecked;
8use core::mem::MaybeUninit;
9
10use crate::{Constrained, Encode, EncodeError, Unconstrained};
11
12/// A type which cannot be constructed.
13pub enum Never {}
14
15impl Unconstrained for Never {}
16
17unsafe impl<W: Constrained, E: ?Sized> Encode<W, E> for Never {
18    fn encode(
19        self,
20        _: &mut E,
21        _: &mut MaybeUninit<W>,
22        _: W::Constraint,
23    ) -> Result<(), EncodeError> {
24        // SAFETY: `Never` cannot exist, so this code can never be reached.
25        unsafe { unreachable_unchecked() }
26    }
27}