Skip to main content

apple_cf/
lib.rs

1//! `apple-cf` — safe, dependency-free Rust bindings for Apple's shared
2//! Core* frameworks.
3//!
4//! This crate is the foundation of the doom-fish macOS Rust suite. It exists
5//! so framework-agnostic types like [`cg::CGRect`], [`iosurface::IOSurface`],
6//! and [`dispatch_queue::DispatchQueue`] don't have to be re-vendored by every crate that
7//! builds on top of `CMSampleBuffer`/`CVPixelBuffer`/etc.
8//!
9//! # Modules
10//!
11//! | Module | Framework | Feature flag |
12//! |---|---|---|
13//! | [`cf`] | Core Foundation value, collection, locale, formatter, and runtime wrappers | — |
14//! | [`raw`] | Exhaustive low-level CoreFoundation/CoreMedia/CoreVideo/IOSurface/Dispatch bindings | — |
15//! | [`cg`] | CoreGraphics value types + bitmap drawing wrappers | `cg` |
16//! | [`iosurface`] | `IOSurface` (zero-copy GPU buffers) | `iosurface` |
17//! | [`dispatch_queue`] | Grand Central Dispatch | `dispatch` |
18//! | [`cm`] | `CoreMedia` time / sample / buffer wrappers | `cm` |
19//! | [`cv`] | `CoreVideo` pixel-buffer wrappers | `cv` |
20//! | [`utils`] | shared FFI helpers (always on) | — |
21//!
22//! # Architecture
23//!
24//! ```text
25//! Safe Rust API (CGRect, CGContext, IOSurface, DispatchQueue, ...)
26//!     ├── exhaustive raw bindings (src/raw)
27//!     ├── direct Apple framework FFI (src/cg/mod.rs)
28//!     └── Swift @_cdecl bridge FFI (src/ffi/mod.rs)
29//!             └── swift-bridge/Sources/...
30//!                     └── Apple Core* frameworks
31//! ```
32
33#![cfg_attr(docsrs, feature(doc_cfg))]
34#![allow(clashing_extern_declarations)]
35
36mod error;
37
38/// Core Foundation value, collection, and runtime wrappers.
39pub mod cf;
40/// Low-level FFI declarations used by the safe wrappers.
41pub mod ffi;
42/// Exhaustive low-level Apple SDK bindings.
43pub mod raw;
44/// Shared helper utilities and FFI shims.
45pub mod utils;
46
47pub use error::CFError;
48
49#[cfg(feature = "cg")]
50#[cfg_attr(docsrs, doc(cfg(feature = "cg")))]
51/// Core Graphics geometry and bitmap-drawing wrappers.
52pub mod cg;
53
54#[cfg(feature = "iosurface")]
55#[cfg_attr(docsrs, doc(cfg(feature = "iosurface")))]
56/// IOSurface ownership and access wrappers.
57pub mod iosurface;
58
59#[cfg(feature = "dispatch")]
60#[cfg_attr(docsrs, doc(cfg(feature = "dispatch")))]
61/// Grand Central Dispatch queue and synchronization wrappers.
62pub mod dispatch_queue;
63
64#[cfg(feature = "cm")]
65#[cfg_attr(docsrs, doc(cfg(feature = "cm")))]
66/// Core Media time, buffer, and format-description wrappers.
67pub mod cm;
68
69#[cfg(feature = "cv")]
70#[cfg_attr(docsrs, doc(cfg(feature = "cv")))]
71/// Core Video buffer and pixel-buffer wrappers.
72pub mod cv;
73
74pub use utils::FourCharCode;
75
76/// Common imports for users of this crate.
77pub mod prelude {
78    pub use crate::cf::{CFArray, CFString, CFType, CFURL};
79    #[cfg(feature = "cg")]
80    pub use crate::cg::{CGPoint, CGRect, CGSize};
81    #[cfg(feature = "cm")]
82    pub use crate::cm::{CMBlockBuffer, CMFormatDescription, CMSampleBuffer, CMTime, CMTimeRange};
83    #[cfg(feature = "cv")]
84    pub use crate::cv::{
85        CVBuffer, CVImageBuffer, CVMetalTextureCache, CVPixelBuffer, CVPixelBufferLockFlags,
86    };
87    #[cfg(feature = "dispatch")]
88    pub use crate::dispatch_queue::{
89        DispatchGroup, DispatchQoS, DispatchQueue, DispatchSemaphore, DispatchSource,
90    };
91    #[cfg(feature = "iosurface")]
92    pub use crate::iosurface::{IOSurface, IOSurfaceLockOptions};
93    pub use crate::utils::FourCharCode;
94}