objc2_foundation/generated/
NSJSONSerialization.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4use objc2::__framework_prelude::*;
5
6use crate::*;
7
8/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsjsonreadingoptions?language=objc)
9// NS_OPTIONS
10#[repr(transparent)]
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
12pub struct NSJSONReadingOptions(pub NSUInteger);
13bitflags::bitflags! {
14    impl NSJSONReadingOptions: NSUInteger {
15        #[doc(alias = "NSJSONReadingMutableContainers")]
16        const MutableContainers = 1<<0;
17        #[doc(alias = "NSJSONReadingMutableLeaves")]
18        const MutableLeaves = 1<<1;
19        #[doc(alias = "NSJSONReadingFragmentsAllowed")]
20        const FragmentsAllowed = 1<<2;
21        #[doc(alias = "NSJSONReadingJSON5Allowed")]
22        const JSON5Allowed = 1<<3;
23        #[doc(alias = "NSJSONReadingTopLevelDictionaryAssumed")]
24        const TopLevelDictionaryAssumed = 1<<4;
25        #[doc(alias = "NSJSONReadingAllowFragments")]
26#[deprecated]
27        const AllowFragments = NSJSONReadingOptions::FragmentsAllowed.0;
28    }
29}
30
31unsafe impl Encode for NSJSONReadingOptions {
32    const ENCODING: Encoding = NSUInteger::ENCODING;
33}
34
35unsafe impl RefEncode for NSJSONReadingOptions {
36    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
37}
38
39/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsjsonwritingoptions?language=objc)
40// NS_OPTIONS
41#[repr(transparent)]
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
43pub struct NSJSONWritingOptions(pub NSUInteger);
44bitflags::bitflags! {
45    impl NSJSONWritingOptions: NSUInteger {
46        #[doc(alias = "NSJSONWritingPrettyPrinted")]
47        const PrettyPrinted = 1<<0;
48        #[doc(alias = "NSJSONWritingSortedKeys")]
49        const SortedKeys = 1<<1;
50        #[doc(alias = "NSJSONWritingFragmentsAllowed")]
51        const FragmentsAllowed = 1<<2;
52        #[doc(alias = "NSJSONWritingWithoutEscapingSlashes")]
53        const WithoutEscapingSlashes = 1<<3;
54    }
55}
56
57unsafe impl Encode for NSJSONWritingOptions {
58    const ENCODING: Encoding = NSUInteger::ENCODING;
59}
60
61unsafe impl RefEncode for NSJSONWritingOptions {
62    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
63}
64
65extern_class!(
66    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsjsonserialization?language=objc)
67    #[unsafe(super(NSObject))]
68    #[derive(Debug, PartialEq, Eq, Hash)]
69    pub struct NSJSONSerialization;
70);
71
72extern_conformance!(
73    unsafe impl NSObjectProtocol for NSJSONSerialization {}
74);
75
76impl NSJSONSerialization {
77    extern_methods!(
78        /// # Safety
79        ///
80        /// `obj` should be of the correct type.
81        #[unsafe(method(isValidJSONObject:))]
82        #[unsafe(method_family = none)]
83        pub unsafe fn isValidJSONObject(obj: &AnyObject) -> bool;
84
85        #[cfg(all(feature = "NSData", feature = "NSError"))]
86        /// # Safety
87        ///
88        /// `obj` should be of the correct type.
89        #[unsafe(method(dataWithJSONObject:options:error:_))]
90        #[unsafe(method_family = none)]
91        pub unsafe fn dataWithJSONObject_options_error(
92            obj: &AnyObject,
93            opt: NSJSONWritingOptions,
94        ) -> Result<Retained<NSData>, Retained<NSError>>;
95
96        #[cfg(all(feature = "NSData", feature = "NSError"))]
97        #[unsafe(method(JSONObjectWithData:options:error:_))]
98        #[unsafe(method_family = none)]
99        pub fn JSONObjectWithData_options_error(
100            data: &NSData,
101            opt: NSJSONReadingOptions,
102        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
103
104        #[cfg(all(feature = "NSError", feature = "NSStream"))]
105        #[unsafe(method(JSONObjectWithStream:options:error:_))]
106        #[unsafe(method_family = none)]
107        pub fn JSONObjectWithStream_options_error(
108            stream: &NSInputStream,
109            opt: NSJSONReadingOptions,
110        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
111    );
112}
113
114/// Methods declared on superclass `NSObject`.
115impl NSJSONSerialization {
116    extern_methods!(
117        #[unsafe(method(init))]
118        #[unsafe(method_family = init)]
119        pub fn init(this: Allocated<Self>) -> Retained<Self>;
120
121        #[unsafe(method(new))]
122        #[unsafe(method_family = new)]
123        pub fn new() -> Retained<Self>;
124    );
125}
126
127impl DefaultRetained for NSJSONSerialization {
128    #[inline]
129    fn default_retained() -> Retained<Self> {
130        Self::new()
131    }
132}