pub fn from_arc<T: AsRef<[u8]> + Sync + Send>(buffer: Arc<T>) -> Self {
        use std::os::raw::c_void;
        use crate::base::{CFAllocator, CFAllocatorContext};

        unsafe {
            let ptr = (*buffer).as_ref().as_ptr() as *const _;
            let len = (*buffer).as_ref().len().to_CFIndex();
            let info = Arc::into_raw(buffer) as *mut c_void;

            extern "C" fn deallocate<T>(_: *mut c_void, info: *mut c_void) {
                unsafe {
                    drop(Arc::from_raw(info as *mut T));
                }
            }

            // Use a separate allocator for each allocation because
            // we need `info` to do the deallocation vs. `ptr`
            let allocator = CFAllocator::new(CFAllocatorContext {
                info,
                version: 0,
                retain: None,
                reallocate: None,
                release: None,
                copyDescription: None,
                allocate: None,
                deallocate: Some(deallocate::<T>),
                preferredSize: None,
            });
            let data_ref =
                CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, ptr, len, allocator.as_CFTypeRef());
            TCFType::wrap_under_create_rule(data_ref)
        }
    }
/// Creates a CFData referencing `buffer` without creating a copy
Creates a CFData referencing `buffer` without creating a copy
Creates a CFData referencing ` buffer ` without creating a copy
pub fn from_arc<T: AsRef<[u8]> + Sync + Send>(buffer: Arc<T>) -> Self {
        use std::os::raw::c_void;
        use crate::base::{CFAllocator, CFAllocatorContext};
        unsafe {
            let ptr = (*buffer).as_ref().as_ptr() as *const _;
            let len = (*buffer).as_ref().len().to_CFIndex();
            let info = Arc::into_raw(buffer) as *mut c_void;
            extern "C" fn deallocate<T>(_: *mut c_void, info: *mut c_void) {
                unsafe {
                    drop(Arc::from_raw(info as *mut T));
                }
            }
            // Use a separate allocator for each allocation because
            // we need `info` to do the deallocation vs. `ptr`
            let allocator = CFAllocator::new(CFAllocatorContext {
                info,
                version: 0,
                retain: None,
                reallocate: None,
                release: None,
                copyDescription: None,
                allocate: None,
                deallocate: Some(deallocate::<T>),
                preferredSize: None,
            });
            let data_ref =
                CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, ptr, len, allocator.as_CFTypeRef());
            TCFType::wrap_under_create_rule(data_ref)
        }
    }
pub fn from_arc < T : AsRef < [ u8 ] > + Sync + Send > ( buffer : Arc < T > ) -> Self { use std :: os :: raw :: c_void ; use crate :: base :: { CFAllocator , CFAllocatorContext } ; unsafe { let ptr = ( * buffer ) . as_ref ( ) . as_ptr ( ) as * const _ ; let len = ( * buffer ) . as_ref ( ) . len ( ) . to_CFIndex ( ) ; let info = Arc :: into_raw ( buffer ) as * mut c_void ; extern " " fn deallocate < T > ( _ : * mut c_void , info : * mut c_void ) { unsafe { drop ( Arc :: from_raw ( info as * mut T ) ) ; } } // Use a separate allocator for each allocation because // we need `info` to do the deallocation vs. `ptr` let allocator = CFAllocator :: new ( CFAllocatorContext { info , version : 0 , retain : None , reallocate : None , release : None , copyDescription : None , allocate : None , deallocate : Some ( deallocate :: < T > ) , preferredSize : None , } ) ; let data_ref = CFDataCreateWithBytesNoCopy ( kCFAllocatorDefault , ptr , len , allocator . as_CFTypeRef ( ) ) ; TCFType :: wrap_under_create_rule ( data_ref ) } }
Creates a CFData referencing `buffer` without creating a copy
Creates a CFData referencing ` buffer ` without creating a copy
buffer
Arc<T>
buffer
Arc<T>