netstack3_base/
test_only.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//! Abstractions enabling test-only behavior.
6
7pub use inner::TestOnlyPartialEq;
8
9// The implementation for test code.
10#[cfg(any(test, feature = "testutils"))]
11mod inner {
12    pub use crate::Counter;
13
14    /// Applies `PartialEq` bounds, only in tests.
15    pub trait TestOnlyPartialEq: PartialEq {}
16
17    impl<T: PartialEq> TestOnlyPartialEq for T {}
18
19    // This implementation is necessary to satisfy trait bounds, but it's
20    // likely a programming error to try to use it.
21    impl PartialEq for Counter {
22        fn eq(&self, _other: &Self) -> bool {
23            panic!("The `Counter` type shouldn't be checked for equality")
24        }
25    }
26}
27
28// The implementation for non-test code
29#[cfg(not(any(test, feature = "testutils")))]
30mod inner {
31
32    /// Applies `PartialEq` bounds, only in tests.
33    pub trait TestOnlyPartialEq {}
34
35    impl<T> TestOnlyPartialEq for T {}
36}