cranelift_control/zero_sized.rs
1//! Shims for ControlPlane when chaos mode is disabled. Enables
2//! unconditional use of the type and its methods throughout cranelift.
3
4/// A shim for ControlPlane when chaos mode is disabled.
5/// Please see the [crate-level documentation](crate).
6#[derive(Debug, Clone, Default)]
7pub struct ControlPlane {
8 /// prevent direct instantiation (use `default` instead)
9 _private: (),
10}
11
12/// A shim for ControlPlane's `Arbitrary` implementation when chaos mode is
13/// disabled. It doesn't consume any bytes and always returns a default
14/// control plane.
15#[cfg(feature = "fuzz")]
16impl arbitrary::Arbitrary<'_> for ControlPlane {
17 fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
18 Ok(Self::default())
19 }
20}
21
22impl ControlPlane {
23 /// Set the [fuel limit](crate#fuel-limit). This variant is used when
24 /// chaos mode is disabled. It doesn't do anything.
25 pub fn set_fuel(&mut self, _fuel: u8) {}
26
27 /// Returns a pseudo-random boolean. This variant is used when chaos
28 /// mode is disabled. It always returns `false`.
29 #[inline]
30 pub fn get_decision(&mut self) -> bool {
31 false
32 }
33
34 /// Returns an arbitrary value. This variant is used when chaos mode is
35 /// disabled. It always returns the default value.
36 #[inline]
37 pub fn get_arbitrary<T: Default>(&mut self) -> T {
38 T::default()
39 }
40
41 /// Shuffles the items in the slice into a pseudo-random permutation.
42 /// This variant is used when chaos mode is disabled. It doesn't do
43 /// anything.
44 #[inline]
45 pub fn shuffle<T>(&mut self, _slice: &mut [T]) {}
46
47 /// Returns a new iterator over the same items as the input iterator in
48 /// a pseudo-random order. This variant is used when chaos mode is
49 /// disabled. It always returns the same order.
50 #[inline]
51 pub fn shuffled<T>(&mut self, iter: impl Iterator<Item = T>) -> impl Iterator<Item = T> {
52 iter
53 }
54}