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
73pub mod provider_ordinals {
74    pub const REGISTER_WATCHER: u64 = 0x91e65af25aae4a9;
75}
76
77pub mod watcher_ordinals {
78    pub const ON_LEVEL_CHANGED: u64 = 0x55d559533407fed9;
79}
80
81mod internal {
82    use super::*;
83    unsafe impl fidl::encoding::TypeMarker for Level {
84        type Owned = Self;
85
86        #[inline(always)]
87        fn inline_align(_context: fidl::encoding::Context) -> usize {
88            std::mem::align_of::<u32>()
89        }
90
91        #[inline(always)]
92        fn inline_size(_context: fidl::encoding::Context) -> usize {
93            std::mem::size_of::<u32>()
94        }
95
96        #[inline(always)]
97        fn encode_is_copy() -> bool {
98            true
99        }
100
101        #[inline(always)]
102        fn decode_is_copy() -> bool {
103            false
104        }
105    }
106
107    impl fidl::encoding::ValueTypeMarker for Level {
108        type Borrowed<'a> = Self;
109        #[inline(always)]
110        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
111            *value
112        }
113    }
114
115    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Level {
116        #[inline]
117        unsafe fn encode(
118            self,
119            encoder: &mut fidl::encoding::Encoder<'_, D>,
120            offset: usize,
121            _depth: fidl::encoding::Depth,
122        ) -> fidl::Result<()> {
123            encoder.debug_check_bounds::<Self>(offset);
124            encoder.write_num(self.into_primitive(), offset);
125            Ok(())
126        }
127    }
128
129    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Level {
130        #[inline(always)]
131        fn new_empty() -> Self {
132            Self::Normal
133        }
134
135        #[inline]
136        unsafe fn decode(
137            &mut self,
138            decoder: &mut fidl::encoding::Decoder<'_, D>,
139            offset: usize,
140            _depth: fidl::encoding::Depth,
141        ) -> fidl::Result<()> {
142            decoder.debug_check_bounds::<Self>(offset);
143            let prim = decoder.read_num::<u32>(offset);
144
145            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
146            Ok(())
147        }
148    }
149
150    impl fidl::encoding::ValueTypeMarker for WatcherOnLevelChangedRequest {
151        type Borrowed<'a> = &'a Self;
152        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
153            value
154        }
155    }
156
157    unsafe impl fidl::encoding::TypeMarker for WatcherOnLevelChangedRequest {
158        type Owned = Self;
159
160        #[inline(always)]
161        fn inline_align(_context: fidl::encoding::Context) -> usize {
162            4
163        }
164
165        #[inline(always)]
166        fn inline_size(_context: fidl::encoding::Context) -> usize {
167            4
168        }
169    }
170
171    unsafe impl<D: fidl::encoding::ResourceDialect>
172        fidl::encoding::Encode<WatcherOnLevelChangedRequest, D> for &WatcherOnLevelChangedRequest
173    {
174        #[inline]
175        unsafe fn encode(
176            self,
177            encoder: &mut fidl::encoding::Encoder<'_, D>,
178            offset: usize,
179            _depth: fidl::encoding::Depth,
180        ) -> fidl::Result<()> {
181            encoder.debug_check_bounds::<WatcherOnLevelChangedRequest>(offset);
182            // Delegate to tuple encoding.
183            fidl::encoding::Encode::<WatcherOnLevelChangedRequest, D>::encode(
184                (<Level as fidl::encoding::ValueTypeMarker>::borrow(&self.level),),
185                encoder,
186                offset,
187                _depth,
188            )
189        }
190    }
191    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Level, D>>
192        fidl::encoding::Encode<WatcherOnLevelChangedRequest, D> for (T0,)
193    {
194        #[inline]
195        unsafe fn encode(
196            self,
197            encoder: &mut fidl::encoding::Encoder<'_, D>,
198            offset: usize,
199            depth: fidl::encoding::Depth,
200        ) -> fidl::Result<()> {
201            encoder.debug_check_bounds::<WatcherOnLevelChangedRequest>(offset);
202            // Zero out padding regions. There's no need to apply masks
203            // because the unmasked parts will be overwritten by fields.
204            // Write the fields.
205            self.0.encode(encoder, offset + 0, depth)?;
206            Ok(())
207        }
208    }
209
210    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
211        for WatcherOnLevelChangedRequest
212    {
213        #[inline(always)]
214        fn new_empty() -> Self {
215            Self { level: fidl::new_empty!(Level, D) }
216        }
217
218        #[inline]
219        unsafe fn decode(
220            &mut self,
221            decoder: &mut fidl::encoding::Decoder<'_, D>,
222            offset: usize,
223            _depth: fidl::encoding::Depth,
224        ) -> fidl::Result<()> {
225            decoder.debug_check_bounds::<Self>(offset);
226            // Verify that padding bytes are zero.
227            fidl::decode!(Level, D, &mut self.level, decoder, offset + 0, _depth)?;
228            Ok(())
229        }
230    }
231}