objc2_core_ml/generated/
MLModel.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// MLModel
12    ///
13    /// Construct a model and evaluate on a specific set of input features.
14    /// Inputs and outputs are accessed via the MLFeatureProvider protocol.
15    /// Returns a model or nil if there is an error.
16    ///
17    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlmodel?language=objc)
18    #[unsafe(super(NSObject))]
19    #[derive(Debug, PartialEq, Eq, Hash)]
20    pub struct MLModel;
21);
22
23extern_conformance!(
24    unsafe impl NSObjectProtocol for MLModel {}
25);
26
27impl MLModel {
28    extern_methods!(
29        #[cfg(feature = "MLModelDescription")]
30        /// A model holds a description of its required inputs and expected outputs.
31        #[unsafe(method(modelDescription))]
32        #[unsafe(method_family = none)]
33        pub unsafe fn modelDescription(&self) -> Retained<MLModelDescription>;
34
35        #[cfg(feature = "MLModelConfiguration")]
36        /// The load-time parameters used to instantiate this MLModel object.
37        #[unsafe(method(configuration))]
38        #[unsafe(method_family = none)]
39        pub unsafe fn configuration(&self) -> Retained<MLModelConfiguration>;
40
41        /// Construct a model with a default MLModelConfiguration object
42        #[unsafe(method(modelWithContentsOfURL:error:_))]
43        #[unsafe(method_family = none)]
44        pub unsafe fn modelWithContentsOfURL_error(
45            url: &NSURL,
46        ) -> Result<Retained<Self>, Retained<NSError>>;
47
48        #[cfg(feature = "MLModelConfiguration")]
49        /// Construct a model given the location of its on-disk representation. Returns nil on error.
50        #[unsafe(method(modelWithContentsOfURL:configuration:error:_))]
51        #[unsafe(method_family = none)]
52        pub unsafe fn modelWithContentsOfURL_configuration_error(
53            url: &NSURL,
54            configuration: &MLModelConfiguration,
55        ) -> Result<Retained<Self>, Retained<NSError>>;
56
57        #[cfg(all(feature = "MLModelConfiguration", feature = "block2"))]
58        /// Construct a model asynchronously given the location of its on-disk representation and configuration.
59        ///
60        /// Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
61        ///
62        ///
63        /// Parameter `url`: the location of its on-disk representation (.mlmodelc directory).
64        ///
65        /// Parameter `configuration`: The model configuration
66        ///
67        /// Parameter `handler`: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
68        #[unsafe(method(loadContentsOfURL:configuration:completionHandler:))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn loadContentsOfURL_configuration_completionHandler(
71            url: &NSURL,
72            configuration: &MLModelConfiguration,
73            handler: &block2::DynBlock<dyn Fn(*mut MLModel, *mut NSError)>,
74        );
75
76        #[cfg(feature = "MLFeatureProvider")]
77        /// Run a prediction on a model synchronously.
78        ///
79        /// This is a convenience overload method of `prediction(from:options:)` that uses the default prediction options.
80        ///
81        /// - Parameters
82        /// - input: The input features to make a prediction from.
83        /// - error: The output parameter to be filled with error information on failure.
84        /// - Returns: The output features from the prediction.
85        #[unsafe(method(predictionFromFeatures:error:_))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn predictionFromFeatures_error(
88            &self,
89            input: &ProtocolObject<dyn MLFeatureProvider>,
90        ) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;
91
92        #[cfg(all(feature = "MLFeatureProvider", feature = "MLPredictionOptions"))]
93        /// Run a prediction on a model synchronously
94        ///
95        /// - Parameters
96        /// - input: The input features to make a prediction from.
97        /// - options: Prediction options to modify how the prediction is run.
98        /// - error: The output parameter to be filled with error information on failure.
99        /// - Returns: The output features from the prediction.
100        #[unsafe(method(predictionFromFeatures:options:error:_))]
101        #[unsafe(method_family = none)]
102        pub unsafe fn predictionFromFeatures_options_error(
103            &self,
104            input: &ProtocolObject<dyn MLFeatureProvider>,
105            options: &MLPredictionOptions,
106        ) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;
107
108        #[cfg(all(feature = "MLFeatureProvider", feature = "block2"))]
109        /// Run a prediction on a model asynchronously.
110        ///
111        /// This is a convenience overload method of `prediction(from:options:) async` that uses the default prediction options.
112        ///
113        /// - Parameters
114        /// - input: The input features to make a prediction from.
115        /// - completionHandler: A block that will be invoked once the prediction has completed successfully or unsuccessfully. On success, it is invoked with a valid model output. On failure, it is invoked with a nil output and NSError
116        #[unsafe(method(predictionFromFeatures:completionHandler:))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn predictionFromFeatures_completionHandler(
119            &self,
120            input: &ProtocolObject<dyn MLFeatureProvider>,
121            completion_handler: &block2::DynBlock<
122                dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
123            >,
124        );
125
126        #[cfg(all(
127            feature = "MLFeatureProvider",
128            feature = "MLPredictionOptions",
129            feature = "block2"
130        ))]
131        /// Run a prediction on a model asynchronously.
132        ///
133        /// - Parameters
134        /// - input: The input features to make a prediction from.
135        /// - options: Prediction options to modify how the prediction is run.
136        /// - completionHandler: A block that will be invoked once the prediction has completed successfully or unsuccessfully. On success, it is invoked with a valid model output. On failure, it is invoked with a nil output and NSError
137        #[unsafe(method(predictionFromFeatures:options:completionHandler:))]
138        #[unsafe(method_family = none)]
139        pub unsafe fn predictionFromFeatures_options_completionHandler(
140            &self,
141            input: &ProtocolObject<dyn MLFeatureProvider>,
142            options: &MLPredictionOptions,
143            completion_handler: &block2::DynBlock<
144                dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
145            >,
146        );
147
148        #[cfg(feature = "MLBatchProvider")]
149        /// Batch prediction without explicit options
150        #[unsafe(method(predictionsFromBatch:error:_))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn predictionsFromBatch_error(
153            &self,
154            input_batch: &ProtocolObject<dyn MLBatchProvider>,
155        ) -> Result<Retained<ProtocolObject<dyn MLBatchProvider>>, Retained<NSError>>;
156
157        #[cfg(all(feature = "MLBatchProvider", feature = "MLPredictionOptions"))]
158        /// Batch prediction with explicit options
159        #[unsafe(method(predictionsFromBatch:options:error:_))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn predictionsFromBatch_options_error(
162            &self,
163            input_batch: &ProtocolObject<dyn MLBatchProvider>,
164            options: &MLPredictionOptions,
165        ) -> Result<Retained<ProtocolObject<dyn MLBatchProvider>>, Retained<NSError>>;
166
167        #[cfg(all(feature = "MLKey", feature = "MLParameterKey"))]
168        /// Provides value for the given parameter. Returns nil on error.
169        #[unsafe(method(parameterValueForKey:error:_))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn parameterValueForKey_error(
172            &self,
173            key: &MLParameterKey,
174        ) -> Result<Retained<AnyObject>, Retained<NSError>>;
175
176        #[cfg(all(
177            feature = "MLModelAsset",
178            feature = "MLModelConfiguration",
179            feature = "block2"
180        ))]
181        /// Construct a model asynchronously from a compiled model asset.
182        ///
183        ///
184        /// Parameter `asset`: Compiled model asset derived from in-memory or on-disk Core ML model
185        ///
186        /// Parameter `configuration`: Model configuration that hold options for loading a model
187        ///
188        /// Parameter `handler`: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
189        #[unsafe(method(loadModelAsset:configuration:completionHandler:))]
190        #[unsafe(method_family = none)]
191        pub unsafe fn loadModelAsset_configuration_completionHandler(
192            asset: &MLModelAsset,
193            configuration: &MLModelConfiguration,
194            handler: &block2::DynBlock<dyn Fn(*mut MLModel, *mut NSError)>,
195        );
196    );
197}
198
199/// Methods declared on superclass `NSObject`.
200impl MLModel {
201    extern_methods!(
202        #[unsafe(method(init))]
203        #[unsafe(method_family = init)]
204        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
205
206        #[unsafe(method(new))]
207        #[unsafe(method_family = new)]
208        pub unsafe fn new() -> Retained<Self>;
209    );
210}