objc2-javascript-core 0.3.2

Bindings to the JavaScriptCore framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ptr::NonNull;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;

use crate::*;

extern "C-unwind" {
    /// Creates a JavaScript string from a CFString.
    ///
    /// This function is optimized to take advantage of cases when
    /// CFStringGetCharactersPtr returns a valid pointer.
    ///
    /// Parameter `string`: The CFString to copy into the new JSString.
    ///
    /// Returns: A JSString containing string. Ownership follows the Create Rule.
    #[cfg(all(feature = "JSBase", feature = "objc2-core-foundation"))]
    pub fn JSStringCreateWithCFString(string: &CFString) -> JSStringRef;
}

/// Creates a CFString from a JavaScript string.
///
/// Parameter `alloc`: The alloc parameter to pass to CFStringCreate.
///
/// Parameter `string`: The JSString to copy into the new CFString.
///
/// Returns: A CFString containing string. Ownership follows the Create Rule.
///
/// # Safety
///
/// - `alloc` might not allow `None`.
/// - `string` must be a valid pointer.
#[cfg(all(feature = "JSBase", feature = "objc2-core-foundation"))]
#[inline]
pub unsafe extern "C-unwind" fn JSStringCopyCFString(
    alloc: Option<&CFAllocator>,
    string: JSStringRef,
) -> Option<CFRetained<CFString>> {
    extern "C-unwind" {
        fn JSStringCopyCFString(
            alloc: Option<&CFAllocator>,
            string: JSStringRef,
        ) -> Option<NonNull<CFString>>;
    }
    let ret = unsafe { JSStringCopyCFString(alloc, string) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}