objc2_javascript_core/generated/
JSStringRefCF.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ptr::NonNull;
4#[cfg(feature = "objc2-core-foundation")]
5use objc2_core_foundation::*;
6
7use crate::*;
8
9extern "C-unwind" {
10    /// Creates a JavaScript string from a CFString.
11    ///
12    /// This function is optimized to take advantage of cases when
13    /// CFStringGetCharactersPtr returns a valid pointer.
14    ///
15    /// Parameter `string`: The CFString to copy into the new JSString.
16    ///
17    /// Returns: A JSString containing string. Ownership follows the Create Rule.
18    #[cfg(all(feature = "JSBase", feature = "objc2-core-foundation"))]
19    pub fn JSStringCreateWithCFString(string: &CFString) -> JSStringRef;
20}
21
22/// Creates a CFString from a JavaScript string.
23///
24/// Parameter `alloc`: The alloc parameter to pass to CFStringCreate.
25///
26/// Parameter `string`: The JSString to copy into the new CFString.
27///
28/// Returns: A CFString containing string. Ownership follows the Create Rule.
29#[cfg(all(feature = "JSBase", feature = "objc2-core-foundation"))]
30#[inline]
31pub unsafe extern "C-unwind" fn JSStringCopyCFString(
32    alloc: Option<&CFAllocator>,
33    string: JSStringRef,
34) -> Option<CFRetained<CFString>> {
35    extern "C-unwind" {
36        fn JSStringCopyCFString(
37            alloc: Option<&CFAllocator>,
38            string: JSStringRef,
39        ) -> Option<NonNull<CFString>>;
40    }
41    let ret = unsafe { JSStringCopyCFString(alloc, string) };
42    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
43}