objc2_foundation/generated/
NSCache.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
9extern_class!(
10    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscache?language=objc)
11    #[unsafe(super(NSObject))]
12    #[derive(Debug, PartialEq, Eq, Hash)]
13    pub struct NSCache<KeyType: ?Sized = AnyObject, ObjectType: ?Sized = AnyObject>;
14);
15
16impl<KeyType: ?Sized + Message, ObjectType: ?Sized + Message> NSCache<KeyType, ObjectType> {
17    /// Unchecked conversion of the generic parameters.
18    ///
19    /// # Safety
20    ///
21    /// The generics must be valid to reinterpret as the given types.
22    #[inline]
23    pub unsafe fn cast_unchecked<NewKeyType: ?Sized + Message, NewObjectType: ?Sized + Message>(
24        &self,
25    ) -> &NSCache<NewKeyType, NewObjectType> {
26        unsafe { &*((self as *const Self).cast()) }
27    }
28}
29
30extern_conformance!(
31    unsafe impl<KeyType: ?Sized, ObjectType: ?Sized> NSObjectProtocol for NSCache<KeyType, ObjectType> {}
32);
33
34impl<KeyType: Message, ObjectType: Message> NSCache<KeyType, ObjectType> {
35    extern_methods!(
36        #[cfg(feature = "NSString")]
37        #[unsafe(method(name))]
38        #[unsafe(method_family = none)]
39        pub unsafe fn name(&self) -> Retained<NSString>;
40
41        #[cfg(feature = "NSString")]
42        /// Setter for [`name`][Self::name].
43        ///
44        /// This is [copied][crate::NSCopying::copy] when set.
45        #[unsafe(method(setName:))]
46        #[unsafe(method_family = none)]
47        pub unsafe fn setName(&self, name: &NSString);
48
49        /// # Safety
50        ///
51        /// This is not retained internally, you must ensure the object is still alive.
52        #[unsafe(method(delegate))]
53        #[unsafe(method_family = none)]
54        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSCacheDelegate>>>;
55
56        /// Setter for [`delegate`][Self::delegate].
57        ///
58        /// # Safety
59        ///
60        /// This is unretained, you must ensure the object is kept alive while in use.
61        #[unsafe(method(setDelegate:))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSCacheDelegate>>);
64
65        #[unsafe(method(objectForKey:))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn objectForKey(&self, key: &KeyType) -> Option<Retained<ObjectType>>;
68
69        #[unsafe(method(setObject:forKey:))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn setObject_forKey(&self, obj: &ObjectType, key: &KeyType);
72
73        #[unsafe(method(setObject:forKey:cost:))]
74        #[unsafe(method_family = none)]
75        pub unsafe fn setObject_forKey_cost(&self, obj: &ObjectType, key: &KeyType, g: NSUInteger);
76
77        #[unsafe(method(removeObjectForKey:))]
78        #[unsafe(method_family = none)]
79        pub unsafe fn removeObjectForKey(&self, key: &KeyType);
80
81        #[unsafe(method(removeAllObjects))]
82        #[unsafe(method_family = none)]
83        pub unsafe fn removeAllObjects(&self);
84
85        #[unsafe(method(totalCostLimit))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn totalCostLimit(&self) -> NSUInteger;
88
89        /// Setter for [`totalCostLimit`][Self::totalCostLimit].
90        #[unsafe(method(setTotalCostLimit:))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn setTotalCostLimit(&self, total_cost_limit: NSUInteger);
93
94        #[unsafe(method(countLimit))]
95        #[unsafe(method_family = none)]
96        pub unsafe fn countLimit(&self) -> NSUInteger;
97
98        /// Setter for [`countLimit`][Self::countLimit].
99        #[unsafe(method(setCountLimit:))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn setCountLimit(&self, count_limit: NSUInteger);
102
103        #[unsafe(method(evictsObjectsWithDiscardedContent))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn evictsObjectsWithDiscardedContent(&self) -> bool;
106
107        /// Setter for [`evictsObjectsWithDiscardedContent`][Self::evictsObjectsWithDiscardedContent].
108        #[unsafe(method(setEvictsObjectsWithDiscardedContent:))]
109        #[unsafe(method_family = none)]
110        pub unsafe fn setEvictsObjectsWithDiscardedContent(
111            &self,
112            evicts_objects_with_discarded_content: bool,
113        );
114    );
115}
116
117/// Methods declared on superclass `NSObject`.
118impl<KeyType: Message, ObjectType: Message> NSCache<KeyType, ObjectType> {
119    extern_methods!(
120        #[unsafe(method(init))]
121        #[unsafe(method_family = init)]
122        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
123
124        #[unsafe(method(new))]
125        #[unsafe(method_family = new)]
126        pub unsafe fn new() -> Retained<Self>;
127    );
128}
129
130extern_protocol!(
131    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nscachedelegate?language=objc)
132    pub unsafe trait NSCacheDelegate: NSObjectProtocol {
133        /// # Safety
134        ///
135        /// - `cache` generic should be of the correct type.
136        /// - `obj` should be of the correct type.
137        #[optional]
138        #[unsafe(method(cache:willEvictObject:))]
139        #[unsafe(method_family = none)]
140        unsafe fn cache_willEvictObject(&self, cache: &NSCache, obj: &AnyObject);
141    }
142);