objc2_core_ml/generated/
MLModelAsset.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    /// A compiled model asset.
12    ///
13    /// `MLModelAsset` is an abstraction of a compiled model, which can be:
14    ///
15    /// - `.mlmodelc` bundle on the file system
16    /// - In-memory model specification
17    ///
18    /// It provides the unified interface to query the model description and to instantiate `MLModel`.
19    ///
20    /// ```swift
21    /// // Creates an object.
22    /// let modelAsset = MLModelAsset(url: modelURL)
23    ///
24    /// // Query the model description
25    /// let description = try await modelAsset.modelDescription
26    ///
27    /// // Query the list of functions in the model asset.
28    /// let functionNames = try await modelAsset.functionNames
29    ///
30    /// // Query the model description of a specific function.
31    /// let descriptionOfMyFunction = try await modelAsset.modelDescription(of: "MyFunction")
32    ///
33    /// // Instantiate `MLModel` for "MyFunction".
34    /// let modelConfiguration = MLModelConfiguration()
35    /// modelConfiguration.functionName = "MyFunction"
36    /// let model = try await MLModel.load(asset: modelAsset, configuration: modelConfiguration)
37    /// ```
38    ///
39    /// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlmodelasset?language=objc)
40    #[unsafe(super(NSObject))]
41    #[derive(Debug, PartialEq, Eq, Hash)]
42    pub struct MLModelAsset;
43);
44
45extern_conformance!(
46    unsafe impl NSObjectProtocol for MLModelAsset {}
47);
48
49impl MLModelAsset {
50    extern_methods!(
51        /// Construct a model asset from the contents of specification data.
52        ///
53        /// - Parameters:
54        /// - specificationData: Contents of .mlmodel as a data blob.
55        /// - error: When the model asset creation fails error is populated with the reason for failure.
56        #[unsafe(method(modelAssetWithSpecificationData:error:_))]
57        #[unsafe(method_family = none)]
58        pub unsafe fn modelAssetWithSpecificationData_error(
59            specification_data: &NSData,
60        ) -> Result<Retained<Self>, Retained<NSError>>;
61
62        /// Construct a model asset from an ML Program specification by replacing blob file references with corresponding in-memory blobs.
63        ///
64        /// An ML Program may use `BlobFileValue` syntax, which stores the blob data in external files and refers them by URL.
65        /// This factory method enables in-memory workflow for such models by using the specified in-memory blob data in place of the external files.
66        ///
67        /// The format of in-memory blobs must be the same as the external files. The dictionary must contain all the reference URLs used in the specification.
68        ///
69        /// - Parameters:
70        /// - specification: Contents of .mlmodel as a data blob.
71        /// - blobMapping: A dictionary with blob URL as the key and blob data as the value.
72        /// - error: When the model asset creation fails error is populated with the reason for failure.
73        #[unsafe(method(modelAssetWithSpecificationData:blobMapping:error:_))]
74        #[unsafe(method_family = none)]
75        pub unsafe fn modelAssetWithSpecificationData_blobMapping_error(
76            specification_data: &NSData,
77            blob_mapping: &NSDictionary<NSURL, NSData>,
78        ) -> Result<Retained<Self>, Retained<NSError>>;
79
80        /// Constructs a ModelAsset from a compiled model URL.
81        ///
82        /// - Parameters:
83        /// - compiledModelURL: Location on the disk where the model asset is present.
84        /// - error: Errors if the model asset is not loadable.
85        ///
86        /// - Returns: a model asset or nil if there is an error.
87        #[unsafe(method(modelAssetWithURL:error:_))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn modelAssetWithURL_error(
90            compiled_model_url: &NSURL,
91        ) -> Result<Retained<Self>, Retained<NSError>>;
92
93        #[cfg(all(feature = "MLModelDescription", feature = "block2"))]
94        /// The default model descripton.
95        ///
96        /// Use this method to get the description of the model such as the feature descriptions, the model author, and other metadata.
97        ///
98        /// For the multi-function model asset, this method vends the description for the default function. Use `modelDescription(for:)` to get the model description of other functions.
99        ///
100        /// ```swift
101        /// let modelAsset = try MLModelAsset(url: modelURL)
102        /// let modelDescription = try await modelAsset.modelDescription()
103        /// print(modelDescription)
104        /// ```
105        #[unsafe(method(modelDescriptionWithCompletionHandler:))]
106        #[unsafe(method_family = none)]
107        pub unsafe fn modelDescriptionWithCompletionHandler(
108            &self,
109            handler: &block2::DynBlock<dyn Fn(*mut MLModelDescription, *mut NSError)>,
110        );
111
112        #[cfg(all(feature = "MLModelDescription", feature = "block2"))]
113        /// The model descripton for a specified function.
114        ///
115        /// Use this method to get the description of the model such as the feature descriptions, the model author, and other metadata.
116        ///
117        /// ```swift
118        /// let modelAsset = try MLModelAsset(url: modelURL)
119        /// let modelDescription = try await modelAsset.modelDescription(of: "my_function")
120        /// print(modelDescription)
121        /// ```
122        #[unsafe(method(modelDescriptionOfFunctionNamed:completionHandler:))]
123        #[unsafe(method_family = none)]
124        pub unsafe fn modelDescriptionOfFunctionNamed_completionHandler(
125            &self,
126            function_name: &NSString,
127            handler: &block2::DynBlock<dyn Fn(*mut MLModelDescription, *mut NSError)>,
128        );
129
130        #[cfg(feature = "block2")]
131        /// The list of function names in the model asset.
132        ///
133        /// Some model types (e.g. ML Program) supports multiple functions. Use this method to query the function names.
134        ///
135        /// The method vends the empty array when the model doesn't use the multi-function configuration.
136        ///
137        /// ```swift
138        /// let modelAsset = try MLModelAsset(url: modelURL)
139        /// let functionNames = try await modelAsset.functionNames
140        /// print(functionNames) // For example, ["my_function1", "my_function2"];
141        /// ```
142        #[unsafe(method(functionNamesWithCompletionHandler:))]
143        #[unsafe(method_family = none)]
144        pub unsafe fn functionNamesWithCompletionHandler(
145            &self,
146            handler: &block2::DynBlock<dyn Fn(*mut NSArray<NSString>, *mut NSError)>,
147        );
148
149        #[unsafe(method(init))]
150        #[unsafe(method_family = init)]
151        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
152
153        #[unsafe(method(new))]
154        #[unsafe(method_family = new)]
155        pub unsafe fn new() -> Retained<Self>;
156    );
157}