objc2_foundation/generated/
NSDecimal.rs1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct NSRoundingMode(pub NSUInteger);
16impl NSRoundingMode {
17 #[doc(alias = "NSRoundPlain")]
18 pub const RoundPlain: Self = Self(0);
19 #[doc(alias = "NSRoundDown")]
20 pub const RoundDown: Self = Self(1);
21 #[doc(alias = "NSRoundUp")]
22 pub const RoundUp: Self = Self(2);
23 #[doc(alias = "NSRoundBankers")]
24 pub const RoundBankers: Self = Self(3);
25}
26
27unsafe impl Encode for NSRoundingMode {
28 const ENCODING: Encoding = NSUInteger::ENCODING;
29}
30
31unsafe impl RefEncode for NSRoundingMode {
32 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35#[repr(transparent)]
38#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
39pub struct NSCalculationError(pub NSUInteger);
40impl NSCalculationError {
41 #[doc(alias = "NSCalculationNoError")]
42 pub const NoError: Self = Self(0);
43 #[doc(alias = "NSCalculationLossOfPrecision")]
44 pub const LossOfPrecision: Self = Self(1);
45 #[doc(alias = "NSCalculationUnderflow")]
46 pub const Underflow: Self = Self(2);
47 #[doc(alias = "NSCalculationOverflow")]
48 pub const Overflow: Self = Self(3);
49 #[doc(alias = "NSCalculationDivideByZero")]
50 pub const DivideByZero: Self = Self(4);
51}
52
53unsafe impl Encode for NSCalculationError {
54 const ENCODING: Encoding = NSUInteger::ENCODING;
55}
56
57unsafe impl RefEncode for NSCalculationError {
58 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
59}
60
61impl NSDecimal {
62 #[doc(alias = "NSDecimalCopy")]
71 #[inline]
72 pub unsafe fn copy(destination: NonNull<NSDecimal>, source: NonNull<NSDecimal>) {
73 extern "C-unwind" {
74 fn NSDecimalCopy(destination: NonNull<NSDecimal>, source: NonNull<NSDecimal>);
75 }
76 unsafe { NSDecimalCopy(destination, source) }
77 }
78
79 #[doc(alias = "NSDecimalCompact")]
83 #[inline]
84 pub unsafe fn compact(number: NonNull<NSDecimal>) {
85 extern "C-unwind" {
86 fn NSDecimalCompact(number: NonNull<NSDecimal>);
87 }
88 unsafe { NSDecimalCompact(number) }
89 }
90
91 #[doc(alias = "NSDecimalCompare")]
96 #[cfg(feature = "NSObjCRuntime")]
97 #[inline]
98 pub unsafe fn compare(
99 left_operand: NonNull<NSDecimal>,
100 right_operand: NonNull<NSDecimal>,
101 ) -> NSComparisonResult {
102 extern "C-unwind" {
103 fn NSDecimalCompare(
104 left_operand: NonNull<NSDecimal>,
105 right_operand: NonNull<NSDecimal>,
106 ) -> NSComparisonResult;
107 }
108 unsafe { NSDecimalCompare(left_operand, right_operand) }
109 }
110
111 #[doc(alias = "NSDecimalRound")]
116 #[inline]
117 pub unsafe fn round(
118 result: NonNull<NSDecimal>,
119 number: NonNull<NSDecimal>,
120 scale: NSInteger,
121 rounding_mode: NSRoundingMode,
122 ) {
123 extern "C-unwind" {
124 fn NSDecimalRound(
125 result: NonNull<NSDecimal>,
126 number: NonNull<NSDecimal>,
127 scale: NSInteger,
128 rounding_mode: NSRoundingMode,
129 );
130 }
131 unsafe { NSDecimalRound(result, number, scale, rounding_mode) }
132 }
133
134 #[doc(alias = "NSDecimalNormalize")]
139 #[inline]
140 pub unsafe fn normalize(
141 number1: NonNull<NSDecimal>,
142 number2: NonNull<NSDecimal>,
143 rounding_mode: NSRoundingMode,
144 ) -> NSCalculationError {
145 extern "C-unwind" {
146 fn NSDecimalNormalize(
147 number1: NonNull<NSDecimal>,
148 number2: NonNull<NSDecimal>,
149 rounding_mode: NSRoundingMode,
150 ) -> NSCalculationError;
151 }
152 unsafe { NSDecimalNormalize(number1, number2, rounding_mode) }
153 }
154
155 #[doc(alias = "NSDecimalAdd")]
161 #[inline]
162 pub unsafe fn add(
163 result: NonNull<NSDecimal>,
164 left_operand: NonNull<NSDecimal>,
165 right_operand: NonNull<NSDecimal>,
166 rounding_mode: NSRoundingMode,
167 ) -> NSCalculationError {
168 extern "C-unwind" {
169 fn NSDecimalAdd(
170 result: NonNull<NSDecimal>,
171 left_operand: NonNull<NSDecimal>,
172 right_operand: NonNull<NSDecimal>,
173 rounding_mode: NSRoundingMode,
174 ) -> NSCalculationError;
175 }
176 unsafe { NSDecimalAdd(result, left_operand, right_operand, rounding_mode) }
177 }
178
179 #[doc(alias = "NSDecimalSubtract")]
185 #[inline]
186 pub unsafe fn subtract(
187 result: NonNull<NSDecimal>,
188 left_operand: NonNull<NSDecimal>,
189 right_operand: NonNull<NSDecimal>,
190 rounding_mode: NSRoundingMode,
191 ) -> NSCalculationError {
192 extern "C-unwind" {
193 fn NSDecimalSubtract(
194 result: NonNull<NSDecimal>,
195 left_operand: NonNull<NSDecimal>,
196 right_operand: NonNull<NSDecimal>,
197 rounding_mode: NSRoundingMode,
198 ) -> NSCalculationError;
199 }
200 unsafe { NSDecimalSubtract(result, left_operand, right_operand, rounding_mode) }
201 }
202
203 #[doc(alias = "NSDecimalMultiply")]
209 #[inline]
210 pub unsafe fn multiply(
211 result: NonNull<NSDecimal>,
212 left_operand: NonNull<NSDecimal>,
213 right_operand: NonNull<NSDecimal>,
214 rounding_mode: NSRoundingMode,
215 ) -> NSCalculationError {
216 extern "C-unwind" {
217 fn NSDecimalMultiply(
218 result: NonNull<NSDecimal>,
219 left_operand: NonNull<NSDecimal>,
220 right_operand: NonNull<NSDecimal>,
221 rounding_mode: NSRoundingMode,
222 ) -> NSCalculationError;
223 }
224 unsafe { NSDecimalMultiply(result, left_operand, right_operand, rounding_mode) }
225 }
226
227 #[doc(alias = "NSDecimalDivide")]
233 #[inline]
234 pub unsafe fn divide(
235 result: NonNull<NSDecimal>,
236 left_operand: NonNull<NSDecimal>,
237 right_operand: NonNull<NSDecimal>,
238 rounding_mode: NSRoundingMode,
239 ) -> NSCalculationError {
240 extern "C-unwind" {
241 fn NSDecimalDivide(
242 result: NonNull<NSDecimal>,
243 left_operand: NonNull<NSDecimal>,
244 right_operand: NonNull<NSDecimal>,
245 rounding_mode: NSRoundingMode,
246 ) -> NSCalculationError;
247 }
248 unsafe { NSDecimalDivide(result, left_operand, right_operand, rounding_mode) }
249 }
250
251 #[doc(alias = "NSDecimalPower")]
256 #[inline]
257 pub unsafe fn power(
258 result: NonNull<NSDecimal>,
259 number: NonNull<NSDecimal>,
260 power: NSUInteger,
261 rounding_mode: NSRoundingMode,
262 ) -> NSCalculationError {
263 extern "C-unwind" {
264 fn NSDecimalPower(
265 result: NonNull<NSDecimal>,
266 number: NonNull<NSDecimal>,
267 power: NSUInteger,
268 rounding_mode: NSRoundingMode,
269 ) -> NSCalculationError;
270 }
271 unsafe { NSDecimalPower(result, number, power, rounding_mode) }
272 }
273
274 #[doc(alias = "NSDecimalMultiplyByPowerOf10")]
279 #[inline]
280 pub unsafe fn multiply_by_power_of10(
281 result: NonNull<NSDecimal>,
282 number: NonNull<NSDecimal>,
283 power: c_short,
284 rounding_mode: NSRoundingMode,
285 ) -> NSCalculationError {
286 extern "C-unwind" {
287 fn NSDecimalMultiplyByPowerOf10(
288 result: NonNull<NSDecimal>,
289 number: NonNull<NSDecimal>,
290 power: c_short,
291 rounding_mode: NSRoundingMode,
292 ) -> NSCalculationError;
293 }
294 unsafe { NSDecimalMultiplyByPowerOf10(result, number, power, rounding_mode) }
295 }
296
297 #[doc(alias = "NSDecimalString")]
302 #[cfg(feature = "NSString")]
303 #[inline]
304 pub unsafe fn string(
305 dcm: NonNull<NSDecimal>,
306 locale: Option<&AnyObject>,
307 ) -> Retained<NSString> {
308 extern "C-unwind" {
309 fn NSDecimalString(
310 dcm: NonNull<NSDecimal>,
311 locale: Option<&AnyObject>,
312 ) -> *mut NSString;
313 }
314 let ret = unsafe { NSDecimalString(dcm, locale) };
315 unsafe { Retained::retain_autoreleased(ret) }
316 .expect("function was marked as returning non-null, but actually returned NULL")
317 }
318}
319
320extern "C-unwind" {
321 #[deprecated = "renamed to `NSDecimal::copy`"]
322 pub fn NSDecimalCopy(destination: NonNull<NSDecimal>, source: NonNull<NSDecimal>);
323}
324
325extern "C-unwind" {
326 #[deprecated = "renamed to `NSDecimal::compact`"]
327 pub fn NSDecimalCompact(number: NonNull<NSDecimal>);
328}
329
330extern "C-unwind" {
331 #[cfg(feature = "NSObjCRuntime")]
332 #[deprecated = "renamed to `NSDecimal::compare`"]
333 pub fn NSDecimalCompare(
334 left_operand: NonNull<NSDecimal>,
335 right_operand: NonNull<NSDecimal>,
336 ) -> NSComparisonResult;
337}
338
339extern "C-unwind" {
340 #[deprecated = "renamed to `NSDecimal::round`"]
341 pub fn NSDecimalRound(
342 result: NonNull<NSDecimal>,
343 number: NonNull<NSDecimal>,
344 scale: NSInteger,
345 rounding_mode: NSRoundingMode,
346 );
347}
348
349extern "C-unwind" {
350 #[deprecated = "renamed to `NSDecimal::normalize`"]
351 pub fn NSDecimalNormalize(
352 number1: NonNull<NSDecimal>,
353 number2: NonNull<NSDecimal>,
354 rounding_mode: NSRoundingMode,
355 ) -> NSCalculationError;
356}
357
358extern "C-unwind" {
359 #[deprecated = "renamed to `NSDecimal::add`"]
360 pub fn NSDecimalAdd(
361 result: NonNull<NSDecimal>,
362 left_operand: NonNull<NSDecimal>,
363 right_operand: NonNull<NSDecimal>,
364 rounding_mode: NSRoundingMode,
365 ) -> NSCalculationError;
366}
367
368extern "C-unwind" {
369 #[deprecated = "renamed to `NSDecimal::subtract`"]
370 pub fn NSDecimalSubtract(
371 result: NonNull<NSDecimal>,
372 left_operand: NonNull<NSDecimal>,
373 right_operand: NonNull<NSDecimal>,
374 rounding_mode: NSRoundingMode,
375 ) -> NSCalculationError;
376}
377
378extern "C-unwind" {
379 #[deprecated = "renamed to `NSDecimal::multiply`"]
380 pub fn NSDecimalMultiply(
381 result: NonNull<NSDecimal>,
382 left_operand: NonNull<NSDecimal>,
383 right_operand: NonNull<NSDecimal>,
384 rounding_mode: NSRoundingMode,
385 ) -> NSCalculationError;
386}
387
388extern "C-unwind" {
389 #[deprecated = "renamed to `NSDecimal::divide`"]
390 pub fn NSDecimalDivide(
391 result: NonNull<NSDecimal>,
392 left_operand: NonNull<NSDecimal>,
393 right_operand: NonNull<NSDecimal>,
394 rounding_mode: NSRoundingMode,
395 ) -> NSCalculationError;
396}
397
398extern "C-unwind" {
399 #[deprecated = "renamed to `NSDecimal::power`"]
400 pub fn NSDecimalPower(
401 result: NonNull<NSDecimal>,
402 number: NonNull<NSDecimal>,
403 power: NSUInteger,
404 rounding_mode: NSRoundingMode,
405 ) -> NSCalculationError;
406}
407
408extern "C-unwind" {
409 #[deprecated = "renamed to `NSDecimal::multiply_by_power_of10`"]
410 pub fn NSDecimalMultiplyByPowerOf10(
411 result: NonNull<NSDecimal>,
412 number: NonNull<NSDecimal>,
413 power: c_short,
414 rounding_mode: NSRoundingMode,
415 ) -> NSCalculationError;
416}
417
418#[cfg(feature = "NSString")]
419#[deprecated = "renamed to `NSDecimal::string`"]
420#[inline]
421pub unsafe extern "C-unwind" fn NSDecimalString(
422 dcm: NonNull<NSDecimal>,
423 locale: Option<&AnyObject>,
424) -> Retained<NSString> {
425 extern "C-unwind" {
426 fn NSDecimalString(dcm: NonNull<NSDecimal>, locale: Option<&AnyObject>) -> *mut NSString;
427 }
428 let ret = unsafe { NSDecimalString(dcm, locale) };
429 unsafe { Retained::retain_autoreleased(ret) }
430 .expect("function was marked as returning non-null, but actually returned NULL")
431}