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 [`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//! | [`cg`] | CoreGraphics value types + bitmap drawing wrappers | `cg` |
15//! | [`iosurface`] | `IOSurface` (zero-copy GPU buffers) | `iosurface` |
16//! | [`dispatch_queue`] | Grand Central Dispatch | `dispatch` |
17//! | [`cm`] | `CoreMedia` time / sample / buffer wrappers | `cm` |
18//! | [`cv`] | `CoreVideo` pixel-buffer wrappers | `cv` |
19//! | [`utils`] | shared FFI helpers (always on) | — |
20//!
21//! # Architecture
22//!
23//! ```text
24//! Safe Rust API (CGRect, CGContext, IOSurface, DispatchQueue, ...)
25//!     ├── direct Apple framework FFI (src/cg/mod.rs)
26//!     └── Swift @_cdecl bridge FFI (src/ffi/mod.rs)
27//!             └── swift-bridge/Sources/...
28//!                     └── Apple Core* frameworks
29//! ```
30
31#![cfg_attr(docsrs, feature(doc_cfg))]
32
33mod error;
34
35pub mod cf;
36pub mod ffi;
37pub mod utils;
38
39pub use error::CFError;
40
41#[cfg(feature = "cg")]
42#[cfg_attr(docsrs, doc(cfg(feature = "cg")))]
43pub mod cg;
44
45#[cfg(feature = "iosurface")]
46#[cfg_attr(docsrs, doc(cfg(feature = "iosurface")))]
47pub mod iosurface;
48
49#[cfg(feature = "dispatch")]
50#[cfg_attr(docsrs, doc(cfg(feature = "dispatch")))]
51pub mod dispatch_queue;
52
53#[cfg(feature = "cm")]
54#[cfg_attr(docsrs, doc(cfg(feature = "cm")))]
55pub mod cm;
56
57#[cfg(feature = "cv")]
58#[cfg_attr(docsrs, doc(cfg(feature = "cv")))]
59pub mod cv;
60
61pub use utils::FourCharCode;
62
63/// Common imports for users of this crate.
64pub mod prelude {
65    pub use crate::cf::{CFArray, CFString, CFType, CFURL};
66    #[cfg(feature = "cg")]
67    pub use crate::cg::{CGPoint, CGRect, CGSize};
68    #[cfg(feature = "cm")]
69    pub use crate::cm::{CMBlockBuffer, CMFormatDescription, CMSampleBuffer, CMTime, CMTimeRange};
70    #[cfg(feature = "cv")]
71    pub use crate::cv::{
72        CVBuffer, CVImageBuffer, CVMetalTextureCache, CVPixelBuffer, CVPixelBufferLockFlags,
73    };
74    #[cfg(feature = "dispatch")]
75    pub use crate::dispatch_queue::{
76        DispatchGroup, DispatchQoS, DispatchQueue, DispatchSemaphore, DispatchSource,
77    };
78    #[cfg(feature = "iosurface")]
79    pub use crate::iosurface::{IOSurface, IOSurfaceLockOptions};
80    pub use crate::utils::FourCharCode;
81}