fidl_fuchsia_memorypressure__common/
fidl_fuchsia_memorypressure__common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// Indicates the memory pressure level.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(u32)]
14pub enum Level {
15    /// The memory pressure level is healthy.
16    ///
17    /// Registered clients are free to hold on to caches and allocate memory
18    /// unrestricted.
19    ///
20    /// However, clients should take care to not proactively re-create caches on a
21    /// transition back to the NORMAL level, causing a memory spike that immediately
22    /// pushes the level over to WARNING again.
23    Normal = 1,
24    /// The memory pressure level is somewhat constrained, and might cross over to
25    /// the critical pressure range if left unchecked.
26    ///
27    /// Registered clients are expected to optimize their operation to limit memory
28    /// usage, rather than for best performance, for example, by reducing cache sizes
29    /// and non-essential memory allocations.
30    ///
31    /// Clients must take care to regulate the amount of work they undertake in
32    /// order to reclaim memory, and ensure that it does not cause visible
33    /// performance degradation. There exists some memory pressure, but not enough
34    /// to justify trading off user responsiveness to reclaim memory.
35    Warning = 2,
36    /// The memory pressure level is very constrained.
37    ///
38    /// Registered clients are expected to drop all non-essential memory, and refrain
39    /// from allocating more memory. Failing to do so might result in the job
40    /// getting terminated, or the system being rebooted in the case of global
41    /// memory pressure.
42    ///
43    /// Clients may undertake expensive work to reclaim memory if required, since
44    /// failing to do so might result in termination. The client might decide that a
45    /// performance hit is a fair tradeoff in this case.
46    Critical = 3,
47}
48
49impl Level {
50    #[inline]
51    pub fn from_primitive(prim: u32) -> Option<Self> {
52        match prim {
53            1 => Some(Self::Normal),
54            2 => Some(Self::Warning),
55            3 => Some(Self::Critical),
56            _ => None,
57        }
58    }
59
60    #[inline]
61    pub const fn into_primitive(self) -> u32 {
62        self as u32
63    }
64}
65
66#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
67pub struct WatcherOnLevelChangedRequest {
68    pub level: Level,
69}
70
71impl fidl::Persistable for WatcherOnLevelChangedRequest {}
72
73mod internal {
74    use super::*;
75    unsafe impl fidl::encoding::TypeMarker for Level {
76        type Owned = Self;
77
78        #[inline(always)]
79        fn inline_align(_context: fidl::encoding::Context) -> usize {
80            std::mem::align_of::<u32>()
81        }
82
83        #[inline(always)]
84        fn inline_size(_context: fidl::encoding::Context) -> usize {
85            std::mem::size_of::<u32>()
86        }
87
88        #[inline(always)]
89        fn encode_is_copy() -> bool {
90            true
91        }
92
93        #[inline(always)]
94        fn decode_is_copy() -> bool {
95            false
96        }
97    }
98
99    impl fidl::encoding::ValueTypeMarker for Level {
100        type Borrowed<'a> = Self;
101        #[inline(always)]
102        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
103            *value
104        }
105    }
106
107    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Level {
108        #[inline]
109        unsafe fn encode(
110            self,
111            encoder: &mut fidl::encoding::Encoder<'_, D>,
112            offset: usize,
113            _depth: fidl::encoding::Depth,
114        ) -> fidl::Result<()> {
115            encoder.debug_check_bounds::<Self>(offset);
116            encoder.write_num(self.into_primitive(), offset);
117            Ok(())
118        }
119    }
120
121    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Level {
122        #[inline(always)]
123        fn new_empty() -> Self {
124            Self::Normal
125        }
126
127        #[inline]
128        unsafe fn decode(
129            &mut self,
130            decoder: &mut fidl::encoding::Decoder<'_, D>,
131            offset: usize,
132            _depth: fidl::encoding::Depth,
133        ) -> fidl::Result<()> {
134            decoder.debug_check_bounds::<Self>(offset);
135            let prim = decoder.read_num::<u32>(offset);
136
137            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
138            Ok(())
139        }
140    }
141
142    impl fidl::encoding::ValueTypeMarker for WatcherOnLevelChangedRequest {
143        type Borrowed<'a> = &'a Self;
144        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
145            value
146        }
147    }
148
149    unsafe impl fidl::encoding::TypeMarker for WatcherOnLevelChangedRequest {
150        type Owned = Self;
151
152        #[inline(always)]
153        fn inline_align(_context: fidl::encoding::Context) -> usize {
154            4
155        }
156
157        #[inline(always)]
158        fn inline_size(_context: fidl::encoding::Context) -> usize {
159            4
160        }
161    }
162
163    unsafe impl<D: fidl::encoding::ResourceDialect>
164        fidl::encoding::Encode<WatcherOnLevelChangedRequest, D> for &WatcherOnLevelChangedRequest
165    {
166        #[inline]
167        unsafe fn encode(
168            self,
169            encoder: &mut fidl::encoding::Encoder<'_, D>,
170            offset: usize,
171            _depth: fidl::encoding::Depth,
172        ) -> fidl::Result<()> {
173            encoder.debug_check_bounds::<WatcherOnLevelChangedRequest>(offset);
174            // Delegate to tuple encoding.
175            fidl::encoding::Encode::<WatcherOnLevelChangedRequest, D>::encode(
176                (<Level as fidl::encoding::ValueTypeMarker>::borrow(&self.level),),
177                encoder,
178                offset,
179                _depth,
180            )
181        }
182    }
183    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Level, D>>
184        fidl::encoding::Encode<WatcherOnLevelChangedRequest, D> for (T0,)
185    {
186        #[inline]
187        unsafe fn encode(
188            self,
189            encoder: &mut fidl::encoding::Encoder<'_, D>,
190            offset: usize,
191            depth: fidl::encoding::Depth,
192        ) -> fidl::Result<()> {
193            encoder.debug_check_bounds::<WatcherOnLevelChangedRequest>(offset);
194            // Zero out padding regions. There's no need to apply masks
195            // because the unmasked parts will be overwritten by fields.
196            // Write the fields.
197            self.0.encode(encoder, offset + 0, depth)?;
198            Ok(())
199        }
200    }
201
202    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
203        for WatcherOnLevelChangedRequest
204    {
205        #[inline(always)]
206        fn new_empty() -> Self {
207            Self { level: fidl::new_empty!(Level, D) }
208        }
209
210        #[inline]
211        unsafe fn decode(
212            &mut self,
213            decoder: &mut fidl::encoding::Decoder<'_, D>,
214            offset: usize,
215            _depth: fidl::encoding::Depth,
216        ) -> fidl::Result<()> {
217            decoder.debug_check_bounds::<Self>(offset);
218            // Verify that padding bytes are zero.
219            fidl::decode!(Level, D, &mut self.level, decoder, offset + 0, _depth)?;
220            Ok(())
221        }
222    }
223}