@@ -10,15 +10,15 @@ use num_enum::TryFromPrimitive;
1010use std:: { convert:: TryFrom , mem:: MaybeUninit , path:: Path , ptr} ;
1111use thiserror:: Error ;
1212
13- use super :: { FunctionPtr , ManagedFunction , RawFunctionPtr , SharedHostfxrLibrary } ;
13+ use super :: { as_managed , FnPtr , ManagedFunction , RawFnPtr , SharedHostfxrLibrary } ;
1414
1515#[ cfg( feature = "net5_0" ) ]
1616use crate :: bindings:: hostfxr:: { get_function_pointer_fn, UNMANAGED_CALLERS_ONLY_METHOD } ;
1717
1818/// A pointer to a function with the default signature.
1919pub type ManagedFunctionWithDefaultSignature = ManagedFunction < component_entry_point_fn > ;
2020/// A pointer to a function with an unknown signature.
21- pub type ManagedFunctionWithUnknownSignature = ManagedFunction < RawFunctionPtr > ;
21+ pub type ManagedFunctionWithUnknownSignature = ManagedFunction < RawFnPtr > ;
2222
2323/// A struct for loading pointers to managed functions for a given [`HostfxrContext`].
2424///
@@ -52,7 +52,7 @@ impl DelegateLoader {
5252 type_name : * const char_t ,
5353 method_name : * const char_t ,
5454 delegate_type_name : * const char_t ,
55- ) -> Result < RawFunctionPtr , GetManagedFunctionError > {
55+ ) -> Result < RawFnPtr , GetManagedFunctionError > {
5656 let mut delegate = MaybeUninit :: uninit ( ) ;
5757
5858 let result = unsafe {
@@ -94,7 +94,7 @@ impl DelegateLoader {
9494 type_name : * const char_t ,
9595 method_name : * const char_t ,
9696 delegate_type_name : * const char_t ,
97- ) -> Result < RawFunctionPtr , GetManagedFunctionError > {
97+ ) -> Result < RawFnPtr , GetManagedFunctionError > {
9898 let mut delegate = MaybeUninit :: uninit ( ) ;
9999
100100 let result = unsafe {
@@ -128,13 +128,13 @@ impl DelegateLoader {
128128 /// Name of the method on the `type_name` to find. The method must be static and must match the signature of `delegate_type_name`.
129129 /// * `delegate_type_name`:
130130 /// Assembly qualified delegate type name for the method signature.
131- pub fn load_assembly_and_get_function < F : FunctionPtr > (
131+ pub fn load_assembly_and_get_function < F : FnPtr > (
132132 & self ,
133133 assembly_path : & PdCStr ,
134134 type_name : & PdCStr ,
135135 method_name : & PdCStr ,
136136 delegate_type_name : & PdCStr ,
137- ) -> Result < ManagedFunction < F :: Managed > , GetManagedFunctionError > {
137+ ) -> Result < ManagedFunction < as_managed ! ( F ) > , GetManagedFunctionError > {
138138 Self :: validate_assembly_path ( assembly_path) ?;
139139 let function = unsafe {
140140 self . load_assembly_and_get_function_pointer_raw (
@@ -144,7 +144,9 @@ impl DelegateLoader {
144144 delegate_type_name. as_ptr ( ) ,
145145 )
146146 } ?;
147- Ok ( ManagedFunction ( unsafe { F :: Managed :: from_ptr ( function) } ) )
147+ Ok ( ManagedFunction ( unsafe {
148+ <as_managed ! ( F ) >:: from_ptr ( function)
149+ } ) )
148150 }
149151
150152 /// Calling this function will load the specified assembly in isolation (into its own `AssemblyLoadContext`)
@@ -177,7 +179,7 @@ impl DelegateLoader {
177179 ptr:: null ( ) ,
178180 )
179181 } ?;
180- Ok ( ManagedFunction ( unsafe { FunctionPtr :: from_ptr ( function) } ) )
182+ Ok ( ManagedFunction ( unsafe { FnPtr :: from_ptr ( function) } ) )
181183 }
182184
183185 /// Calling this function will load the specified assembly in isolation (into its own `AssemblyLoadContext`)
@@ -199,12 +201,12 @@ impl DelegateLoader {
199201 /// [UnmanagedCallersOnly]: <https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.unmanagedcallersonlyattribute>
200202 #[ cfg( feature = "net5_0" ) ]
201203 #[ cfg_attr( feature = "doc-cfg" , doc( cfg( feature = "net5_0" ) ) ) ]
202- pub fn load_assembly_and_get_function_with_unmanaged_callers_only < F : FunctionPtr > (
204+ pub fn load_assembly_and_get_function_with_unmanaged_callers_only < F : FnPtr > (
203205 & self ,
204206 assembly_path : & PdCStr ,
205207 type_name : & PdCStr ,
206208 method_name : & PdCStr ,
207- ) -> Result < ManagedFunction < F :: Managed > , GetManagedFunctionError > {
209+ ) -> Result < ManagedFunction < as_managed ! ( F ) > , GetManagedFunctionError > {
208210 Self :: validate_assembly_path ( assembly_path) ?;
209211 let function = unsafe {
210212 self . load_assembly_and_get_function_pointer_raw (
@@ -214,7 +216,9 @@ impl DelegateLoader {
214216 UNMANAGED_CALLERS_ONLY_METHOD ,
215217 )
216218 } ?;
217- Ok ( ManagedFunction ( unsafe { F :: Managed :: from_ptr ( function) } ) )
219+ Ok ( ManagedFunction ( unsafe {
220+ <as_managed ! ( F ) >:: from_ptr ( function)
221+ } ) )
218222 }
219223
220224 /// Calling this function will find the specified type and method and return a native function pointer to that method.
@@ -229,20 +233,22 @@ impl DelegateLoader {
229233 /// Assembly qualified delegate type name for the method signature.
230234 #[ cfg( feature = "net5_0" ) ]
231235 #[ cfg_attr( feature = "doc-cfg" , doc( cfg( feature = "net5_0" ) ) ) ]
232- pub fn get_function < F : FunctionPtr > (
236+ pub fn get_function < F : FnPtr > (
233237 & self ,
234238 type_name : & PdCStr ,
235239 method_name : & PdCStr ,
236240 delegate_type_name : & PdCStr ,
237- ) -> Result < ManagedFunction < F :: Managed > , GetManagedFunctionError > {
241+ ) -> Result < ManagedFunction < as_managed ! ( F ) > , GetManagedFunctionError > {
238242 let function = unsafe {
239243 self . get_function_pointer_raw (
240244 type_name. as_ptr ( ) ,
241245 method_name. as_ptr ( ) ,
242246 delegate_type_name. as_ptr ( ) ,
243247 )
244248 } ?;
245- Ok ( ManagedFunction ( unsafe { F :: Managed :: from_ptr ( function) } ) )
249+ Ok ( ManagedFunction ( unsafe {
250+ <as_managed ! ( F ) >:: from_ptr ( function)
251+ } ) )
246252 }
247253
248254 /// Calling this function will find the specified type and method and return a native function pointer to that method.
@@ -263,7 +269,7 @@ impl DelegateLoader {
263269 let function = unsafe {
264270 self . get_function_pointer_raw ( type_name. as_ptr ( ) , method_name. as_ptr ( ) , ptr:: null ( ) )
265271 } ?;
266- Ok ( ManagedFunction ( unsafe { FunctionPtr :: from_ptr ( function) } ) )
272+ Ok ( ManagedFunction ( unsafe { FnPtr :: from_ptr ( function) } ) )
267273 }
268274
269275 /// Calling this function will find the specified type and method and return a native function pointer to that method.
@@ -279,19 +285,21 @@ impl DelegateLoader {
279285 /// [`UnmanagedCallersOnly`]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.unmanagedcallersonlyattribute
280286 #[ cfg( feature = "net5_0" ) ]
281287 #[ cfg_attr( feature = "doc-cfg" , doc( cfg( feature = "net5_0" ) ) ) ]
282- pub fn get_function_with_unmanaged_callers_only < F : FunctionPtr > (
288+ pub fn get_function_with_unmanaged_callers_only < F : FnPtr > (
283289 & self ,
284290 type_name : & PdCStr ,
285291 method_name : & PdCStr ,
286- ) -> Result < ManagedFunction < F :: Managed > , GetManagedFunctionError > {
292+ ) -> Result < ManagedFunction < as_managed ! ( F ) > , GetManagedFunctionError > {
287293 let function = unsafe {
288294 self . get_function_pointer_raw (
289295 type_name. as_ptr ( ) ,
290296 method_name. as_ptr ( ) ,
291297 UNMANAGED_CALLERS_ONLY_METHOD ,
292298 )
293299 } ?;
294- Ok ( ManagedFunction ( unsafe { F :: Managed :: from_ptr ( function) } ) )
300+ Ok ( ManagedFunction ( unsafe {
301+ <as_managed ! ( F ) >:: from_ptr ( function)
302+ } ) )
295303 }
296304}
297305
@@ -330,12 +338,12 @@ impl AssemblyDelegateLoader {
330338 /// Name of the method on the `type_name` to find. The method must be static and must match the signature of `delegate_type_name`.
331339 /// * `delegate_type_name`:
332340 /// Assembly qualified delegate type name for the method signature.
333- pub fn get_function < F : FunctionPtr > (
341+ pub fn get_function < F : FnPtr > (
334342 & self ,
335343 type_name : & PdCStr ,
336344 method_name : & PdCStr ,
337345 delegate_type_name : & PdCStr ,
338- ) -> Result < ManagedFunction < F :: Managed > , GetManagedFunctionError > {
346+ ) -> Result < ManagedFunction < as_managed ! ( F ) > , GetManagedFunctionError > {
339347 self . loader . load_assembly_and_get_function :: < F > (
340348 self . assembly_path . as_ref ( ) ,
341349 type_name,
@@ -385,11 +393,11 @@ impl AssemblyDelegateLoader {
385393 /// [`UnmanagedCallersOnly`]: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.unmanagedcallersonlyattribute
386394 #[ cfg( feature = "net5_0" ) ]
387395 #[ cfg_attr( feature = "doc-cfg" , doc( cfg( feature = "net5_0" ) ) ) ]
388- pub fn get_function_with_unmanaged_callers_only < F : FunctionPtr > (
396+ pub fn get_function_with_unmanaged_callers_only < F : FnPtr > (
389397 & self ,
390398 type_name : & PdCStr ,
391399 method_name : & PdCStr ,
392- ) -> Result < ManagedFunction < F :: Managed > , GetManagedFunctionError > {
400+ ) -> Result < ManagedFunction < as_managed ! ( F ) > , GetManagedFunctionError > {
393401 self . loader
394402 . load_assembly_and_get_function_with_unmanaged_callers_only :: < F > (
395403 self . assembly_path . as_ref ( ) ,
0 commit comments