Available on crate feature
async only.Expand description
Async API for VisionKit
Enabled with the async Cargo feature. Every type here is an executor-agnostic
Future backed by a C callback fired from a Swift Task { … } thunk.
§Available types
| Type | Wraps |
|---|---|
AsyncImageAnalyzer | ImageAnalyzer.analyze(imageAt:orientation:configuration:) async throws |
AsyncOverlaySubjects | ImageAnalysisOverlayView.subjects async and .subject(at:) async |
§Platform notes
On macOS the subject APIs (subjects, subject(at:)) live on
ImageAnalysisOverlayView (Rust: LiveTextInteraction), not on
ImageAnalysis as on iOS. AsyncOverlaySubjects wraps this macOS surface.
DataScannerViewController is an iOS-only API and is not available on
macOS. Its multi-delegate live-scan surface is a Tier-2 (Stream) concern in
any case. No wrappers are provided here.
§Design
- Each async Swift API gets a
@_cdeclthunk that accepts a C callback(result, error, ctx)and actxopaque pointer. The thunk spawns a SwiftTask, awaits the Apple API, then fires the callback. - The Rust side wraps that in a typed
Futurenewtype backed byAsyncCompletionFuture<T>and maps theStringerror toVisionKitError. - Works with any async executor (
pollster, Tokio, async-std, …).
§Example
use visionkit::async_api::AsyncImageAnalyzer;
use visionkit::{ImageAnalysisTypes, ImageAnalyzerConfiguration, ImageOrientation};
let cfg = ImageAnalyzerConfiguration::new(ImageAnalysisTypes::TEXT);
let analysis = AsyncImageAnalyzer::new()?
.analyze_image_at_path("/path/to/image.png", ImageOrientation::Up, &cfg)?
.await?;
println!("transcript: {}", analysis.transcript()?);Structs§
- Analysis
Subject Bounds - Bounds rectangle for an
ImageAnalysisOverlayView.Subject(macOS) orImageAnalysisInteraction.Subject(iOS). - Analyze
Image Future - Future returned by
AsyncImageAnalyzer::analyze_image_at_path. - Async
Image Analyzer - True-async entry point for
ImageAnalyzer.analyze(imageAt:orientation:configuration:). - Async
Overlay Subjects - True-async entry point for
ImageAnalysisOverlayView.subjectsandImageAnalysisOverlayView.subject(at:)(macOS). - Subject
AtFuture - Future returned by
AsyncOverlaySubjects::subject_at. - Subjects
Future - Future returned by
AsyncOverlaySubjects::subjects.
Functions§
- block_
on - Drive a VisionKit async future to completion while pumping the Obj-C main run loop between polls.