nstd_sys/core/
ity.rs

1//! Provides functions for examining and operating on integral types.
2use crate::{
3    NSTDInt, NSTDInt16, NSTDInt32, NSTDInt64, NSTDInt8, NSTDUInt, NSTDUInt16, NSTDUInt32,
4    NSTDUInt64, NSTDUInt8,
5};
6use nstdapi::nstdapi;
7
8/// Generates the `min` and `max` functions.
9macro_rules! gen_min_max {
10    (
11        $(#[$minmeta:meta])*
12        $minname: ident,
13        $(#[$maxmeta:meta])*
14        $maxname: ident,
15        $T: ty
16    ) => {
17        $(#[$minmeta])*
18        #[inline]
19        #[nstdapi]
20        pub const fn $minname() -> $T {
21            <$T>::MIN
22        }
23
24        $(#[$maxmeta])*
25        #[inline]
26        #[nstdapi]
27        pub const fn $maxname() -> $T {
28            <$T>::MAX
29        }
30    };
31}
32gen_min_max!(
33    /// Returns the smallest value representable by `NSTDInt`.
34    ///
35    /// # Returns
36    ///
37    /// `NSTDInt min` - The smallest value representable by `NSTDInt`.
38    ///
39    /// # Examples
40    ///
41    /// ```
42    /// use nstd_sys::core::ity::nstd_core_ity_min_int;
43    ///
44    /// # unsafe {
45    /// assert!(nstd_core_ity_min_int() == isize::MIN);
46    /// # }
47    /// ```
48    nstd_core_ity_min_int,
49    /// Returns the largest value representable by `NSTDInt`.
50    ///
51    /// # Returns
52    ///
53    /// `NSTDInt max` - The largest value representable by `NSTDInt`.
54    ///
55    /// # Examples
56    ///
57    /// ```
58    /// use nstd_sys::core::ity::nstd_core_ity_max_int;
59    ///
60    /// # unsafe {
61    /// assert!(nstd_core_ity_max_int() == isize::MAX);
62    /// # }
63    /// ```
64    nstd_core_ity_max_int,
65    NSTDInt
66);
67gen_min_max!(
68    /// Returns the smallest value representable by `NSTDUInt`.
69    ///
70    /// # Returns
71    ///
72    /// `NSTDUInt min` - The smallest value representable by `NSTDUInt`.
73    ///
74    /// # Examples
75    ///
76    /// ```
77    /// use nstd_sys::core::ity::nstd_core_ity_min_uint;
78    ///
79    /// # unsafe {
80    /// assert!(nstd_core_ity_min_uint() == usize::MIN);
81    /// # }
82    /// ```
83    nstd_core_ity_min_uint,
84    /// Returns the largest value representable by `NSTDUInt`.
85    ///
86    /// # Returns
87    ///
88    /// `NSTDUInt max` - The largest value representable by `NSTDUInt`.
89    ///
90    /// # Examples
91    ///
92    /// ```
93    /// use nstd_sys::core::ity::nstd_core_ity_max_uint;
94    ///
95    /// # unsafe {
96    /// assert!(nstd_core_ity_max_uint() == usize::MAX);
97    /// # }
98    /// ```
99    nstd_core_ity_max_uint,
100    NSTDUInt
101);
102gen_min_max!(
103    /// Returns the smallest value representable by `NSTDInt8`.
104    ///
105    /// # Returns
106    ///
107    /// `NSTDInt8 min` - The smallest value representable by `NSTDInt8`.
108    ///
109    /// # Examples
110    ///
111    /// ```
112    /// use nstd_sys::core::ity::nstd_core_ity_min_i8;
113    ///
114    /// # unsafe {
115    /// assert!(nstd_core_ity_min_i8() == i8::MIN);
116    /// # }
117    /// ```
118    nstd_core_ity_min_i8,
119    /// Returns the largest value representable by `NSTDInt8`.
120    ///
121    /// # Returns
122    ///
123    /// `NSTDInt8 max` - The largest value representable by `NSTDInt8`.
124    ///
125    /// # Examples
126    ///
127    /// ```
128    /// use nstd_sys::core::ity::nstd_core_ity_max_i8;
129    ///
130    /// # unsafe {
131    /// assert!(nstd_core_ity_max_i8() == i8::MAX);
132    /// # }
133    /// ```
134    nstd_core_ity_max_i8,
135    NSTDInt8
136);
137gen_min_max!(
138    /// Returns the smallest value representable by `NSTDUInt8`.
139    ///
140    /// # Returns
141    ///
142    /// `NSTDUInt8 min` - The smallest value representable by `NSTDUInt8`.
143    ///
144    /// # Examples
145    ///
146    /// ```
147    /// use nstd_sys::core::ity::nstd_core_ity_min_u8;
148    ///
149    /// # unsafe {
150    /// assert!(nstd_core_ity_min_u8() == u8::MIN);
151    /// # }
152    /// ```
153    nstd_core_ity_min_u8,
154    /// Returns the largest value representable by `NSTDUInt8`.
155    ///
156    /// # Returns
157    ///
158    /// `NSTDUInt8 max` - The largest value representable by `NSTDUInt8`.
159    ///
160    /// # Examples
161    ///
162    /// ```
163    /// use nstd_sys::core::ity::nstd_core_ity_max_u8;
164    ///
165    /// # unsafe {
166    /// assert!(nstd_core_ity_max_u8() == u8::MAX);
167    /// # }
168    /// ```
169    nstd_core_ity_max_u8,
170    NSTDUInt8
171);
172gen_min_max!(
173    /// Returns the smallest value representable by `NSTDInt16`.
174    ///
175    /// # Returns
176    ///
177    /// `NSTDInt16 min` - The smallest value representable by `NSTDInt16`.
178    ///
179    /// # Examples
180    ///
181    /// ```
182    /// use nstd_sys::core::ity::nstd_core_ity_min_i16;
183    ///
184    /// # unsafe {
185    /// assert!(nstd_core_ity_min_i16() == i16::MIN);
186    /// # }
187    /// ```
188    nstd_core_ity_min_i16,
189    /// Returns the largest value representable by `NSTDInt16`.
190    ///
191    /// # Returns
192    ///
193    /// `NSTDInt16 max` - The largest value representable by `NSTDInt16`.
194    ///
195    /// # Examples
196    ///
197    /// ```
198    /// use nstd_sys::core::ity::nstd_core_ity_max_i16;
199    ///
200    /// # unsafe {
201    /// assert!(nstd_core_ity_max_i16() == i16::MAX);
202    /// # }
203    /// ```
204    nstd_core_ity_max_i16,
205    NSTDInt16
206);
207gen_min_max!(
208    /// Returns the smallest value representable by `NSTDUInt16`.
209    ///
210    /// # Returns
211    ///
212    /// `NSTDUInt16 min` - The smallest value representable by `NSTDUInt16`.
213    ///
214    /// # Examples
215    ///
216    /// ```
217    /// use nstd_sys::core::ity::nstd_core_ity_min_u16;
218    ///
219    /// # unsafe {
220    /// assert!(nstd_core_ity_min_u16() == u16::MIN);
221    /// # }
222    /// ```
223    nstd_core_ity_min_u16,
224    /// Returns the largest value representable by `NSTDUInt16`.
225    ///
226    /// # Returns
227    ///
228    /// `NSTDUInt16 max` - The largest value representable by `NSTDUInt16`.
229    ///
230    /// # Examples
231    ///
232    /// ```
233    /// use nstd_sys::core::ity::nstd_core_ity_max_u16;
234    ///
235    /// # unsafe {
236    /// assert!(nstd_core_ity_max_u16() == u16::MAX);
237    /// # }
238    /// ```
239    nstd_core_ity_max_u16,
240    NSTDUInt16
241);
242gen_min_max!(
243    /// Returns the smallest value representable by `NSTDInt32`.
244    ///
245    /// # Returns
246    ///
247    /// `NSTDInt32 min` - The smallest value representable by `NSTDInt32`.
248    ///
249    /// # Examples
250    ///
251    /// ```
252    /// use nstd_sys::core::ity::nstd_core_ity_min_i32;
253    ///
254    /// # unsafe {
255    /// assert!(nstd_core_ity_min_i32() == i32::MIN);
256    /// # }
257    /// ```
258    nstd_core_ity_min_i32,
259    /// Returns the largest value representable by `NSTDInt32`.
260    ///
261    /// # Returns
262    ///
263    /// `NSTDInt32 max` - The largest value representable by `NSTDInt32`.
264    ///
265    /// # Examples
266    ///
267    /// ```
268    /// use nstd_sys::core::ity::nstd_core_ity_max_i32;
269    ///
270    /// # unsafe {
271    /// assert!(nstd_core_ity_max_i32() == i32::MAX);
272    /// # }
273    /// ```
274    nstd_core_ity_max_i32,
275    NSTDInt32
276);
277gen_min_max!(
278    /// Returns the smallest value representable by `NSTDUInt32`.
279    ///
280    /// # Returns
281    ///
282    /// `NSTDUInt32 min` - The smallest value representable by `NSTDUInt32`.
283    ///
284    /// # Examples
285    ///
286    /// ```
287    /// use nstd_sys::core::ity::nstd_core_ity_min_u32;
288    ///
289    /// # unsafe {
290    /// assert!(nstd_core_ity_min_u32() == u32::MIN);
291    /// # }
292    /// ```
293    nstd_core_ity_min_u32,
294    /// Returns the largest value representable by `NSTDUInt32`.
295    ///
296    /// # Returns
297    ///
298    /// `NSTDUInt32 max` - The largest value representable by `NSTDUInt32`.
299    ///
300    /// # Examples
301    ///
302    /// ```
303    /// use nstd_sys::core::ity::nstd_core_ity_max_u32;
304    ///
305    /// # unsafe {
306    /// assert!(nstd_core_ity_max_u32() == u32::MAX);
307    /// # }
308    /// ```
309    nstd_core_ity_max_u32,
310    NSTDUInt32
311);
312gen_min_max!(
313    /// Returns the smallest value representable by `NSTDInt64`.
314    ///
315    /// # Returns
316    ///
317    /// `NSTDInt64 min` - The smallest value representable by `NSTDInt64`.
318    ///
319    /// # Examples
320    ///
321    /// ```
322    /// use nstd_sys::core::ity::nstd_core_ity_min_i64;
323    ///
324    /// # unsafe {
325    /// assert!(nstd_core_ity_min_i64() == i64::MIN);
326    /// # }
327    /// ```
328    nstd_core_ity_min_i64,
329    /// Returns the largest value representable by `NSTDInt64`.
330    ///
331    /// # Returns
332    ///
333    /// `NSTDInt64 max` - The largest value representable by `NSTDInt64`.
334    ///
335    /// # Examples
336    ///
337    /// ```
338    /// use nstd_sys::core::ity::nstd_core_ity_max_i64;
339    ///
340    /// # unsafe {
341    /// assert!(nstd_core_ity_max_i64() == i64::MAX);
342    /// # }
343    /// ```
344    nstd_core_ity_max_i64,
345    NSTDInt64
346);
347gen_min_max!(
348    /// Returns the smallest value representable by `NSTDUInt64`.
349    ///
350    /// # Returns
351    ///
352    /// `NSTDUInt64 min` - The smallest value representable by `NSTDUInt64`.
353    ///
354    /// # Examples
355    ///
356    /// ```
357    /// use nstd_sys::core::ity::nstd_core_ity_min_u64;
358    ///
359    /// # unsafe {
360    /// assert!(nstd_core_ity_min_u64() == u64::MIN);
361    /// # }
362    /// ```
363    nstd_core_ity_min_u64,
364    /// Returns the largest value representable by `NSTDUInt64`.
365    ///
366    /// # Returns
367    ///
368    /// `NSTDUInt64 max` - The largest value representable by `NSTDUInt64`.
369    ///
370    /// # Examples
371    ///
372    /// ```
373    /// use nstd_sys::core::ity::nstd_core_ity_max_u64;
374    ///
375    /// # unsafe {
376    /// assert!(nstd_core_ity_max_u64() == u64::MAX);
377    /// # }
378    /// ```
379    nstd_core_ity_max_u64,
380    NSTDUInt64
381);