objc2_foundation/generated/
NSDecimal.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9/// *************    Type definitions        **********
10///
11/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsroundingmode?language=objc)
12// NS_ENUM
13#[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/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscalculationerror?language=objc)
36// NS_ENUM
37#[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
61// TODO: pub fn NSDecimalIsNotANumber(dcm: NonNull<NSDecimal>,) -> Bool;
62
63extern "C-unwind" {
64    /// *************    Operations        **********
65    pub fn NSDecimalCopy(destination: NonNull<NSDecimal>, source: NonNull<NSDecimal>);
66}
67
68extern "C-unwind" {
69    pub fn NSDecimalCompact(number: NonNull<NSDecimal>);
70}
71
72extern "C-unwind" {
73    #[cfg(feature = "NSObjCRuntime")]
74    pub fn NSDecimalCompare(
75        left_operand: NonNull<NSDecimal>,
76        right_operand: NonNull<NSDecimal>,
77    ) -> NSComparisonResult;
78}
79
80extern "C-unwind" {
81    pub fn NSDecimalRound(
82        result: NonNull<NSDecimal>,
83        number: NonNull<NSDecimal>,
84        scale: NSInteger,
85        rounding_mode: NSRoundingMode,
86    );
87}
88
89extern "C-unwind" {
90    pub fn NSDecimalNormalize(
91        number1: NonNull<NSDecimal>,
92        number2: NonNull<NSDecimal>,
93        rounding_mode: NSRoundingMode,
94    ) -> NSCalculationError;
95}
96
97extern "C-unwind" {
98    pub fn NSDecimalAdd(
99        result: NonNull<NSDecimal>,
100        left_operand: NonNull<NSDecimal>,
101        right_operand: NonNull<NSDecimal>,
102        rounding_mode: NSRoundingMode,
103    ) -> NSCalculationError;
104}
105
106extern "C-unwind" {
107    pub fn NSDecimalSubtract(
108        result: NonNull<NSDecimal>,
109        left_operand: NonNull<NSDecimal>,
110        right_operand: NonNull<NSDecimal>,
111        rounding_mode: NSRoundingMode,
112    ) -> NSCalculationError;
113}
114
115extern "C-unwind" {
116    pub fn NSDecimalMultiply(
117        result: NonNull<NSDecimal>,
118        left_operand: NonNull<NSDecimal>,
119        right_operand: NonNull<NSDecimal>,
120        rounding_mode: NSRoundingMode,
121    ) -> NSCalculationError;
122}
123
124extern "C-unwind" {
125    pub fn NSDecimalDivide(
126        result: NonNull<NSDecimal>,
127        left_operand: NonNull<NSDecimal>,
128        right_operand: NonNull<NSDecimal>,
129        rounding_mode: NSRoundingMode,
130    ) -> NSCalculationError;
131}
132
133extern "C-unwind" {
134    pub fn NSDecimalPower(
135        result: NonNull<NSDecimal>,
136        number: NonNull<NSDecimal>,
137        power: NSUInteger,
138        rounding_mode: NSRoundingMode,
139    ) -> NSCalculationError;
140}
141
142extern "C-unwind" {
143    pub fn NSDecimalMultiplyByPowerOf10(
144        result: NonNull<NSDecimal>,
145        number: NonNull<NSDecimal>,
146        power: c_short,
147        rounding_mode: NSRoundingMode,
148    ) -> NSCalculationError;
149}
150
151#[cfg(feature = "NSString")]
152#[inline]
153pub unsafe extern "C-unwind" fn NSDecimalString(
154    dcm: NonNull<NSDecimal>,
155    locale: Option<&AnyObject>,
156) -> Retained<NSString> {
157    extern "C-unwind" {
158        fn NSDecimalString(dcm: NonNull<NSDecimal>, locale: Option<&AnyObject>) -> *mut NSString;
159    }
160    let ret = unsafe { NSDecimalString(dcm, locale) };
161    unsafe { Retained::retain_autoreleased(ret) }
162        .expect("function was marked as returning non-null, but actually returned NULL")
163}