Expand description
§photokit
Safe Rust bindings for Apple’s Photos framework on macOS.
Status: v0.3.0 adds the Tier-1
async_apimodule on top of the fully audited Photos.framework surface, with executor-agnostic futures for authorization,performChanges, image requests, and live-photo editing callbacks.
§Quick start
use photokit::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let library = PHPhotoLibrary::shared()?;
println!("status: {:?}", PHPhotoLibrary::authorization_status());
let assets = PHAsset::fetch(&PHFetchOptions::default())?;
println!("assets: {}", assets.len());
if let Some(asset) = assets.first() {
let manager = PHImageManager::shared()?;
let request = manager.request_image_data(
asset,
&PHImageRequest::new(320.0, 240.0, PHImageContentMode::AspectFit),
)?;
let image = request.wait(10_000)?;
println!("image bytes: {}", image.data().len());
}
let _ = library.fetch_asset_collections(&PHFetchOptions::default())?;
Ok(())
}§Async API
Enable the async feature to access non-blocking wrappers for Photos.framework completion-handler APIs:
[dependencies]
photokit = { version = "0.3", features = ["async"] }use photokit::async_api::AsyncPHPhotoLibrary;
use photokit::PHAccessLevel;
let status = AsyncPHPhotoLibrary::request_authorization(PHAccessLevel::ReadWrite).await?;All async types implement std::future::Future and are executor-agnostic.
See async_api for the full API surface.
§Highlights
PHPhotoLibraryauthorization helpers plus summary/detailed change observers, availability observers, and persistent-change history helpers.PHAsset,PHCollection,PHAssetCollection, andPHCollectionListfetch helpers with typed subtype/source/resource wrappers.PHChangeRequestbuilders for asset, album, folder, and project mutation flows.PHImageManager/PHCachingImageManagerrequest handles for images, image data, live photos, video requests, and caching.PHAssetResourceManagertransfer helpers for reading or writing asset resources.PHContentEditingInput/PHContentEditingOutputplusPHLivePhotoEditingContextfor non-destructive editing workflows.PHCloudIdentifierbatch lookup helpers and richer Photos-specific error metadata.
§Coverage audit
See COVERAGE.md for the framework audit, implemented rows, partial rows, and deferred macOS-unavailable or deprecated APIs.
§Examples
The crate ships with numbered examples covering every logical area:
01_photokit_smoke02_phasset_fetch03_phasset_collection_fetch04_phcollection_list_fetch05_phphoto_library_authorization06_phimage_manager_requests07_phfetch_result_methods08_phchange_observer09_phcontent_editing_input10_phcontent_editing_output11_phobject_change_details12_phfetch_options_builder13_phasset_creation_request14_phlive_photo15_phcloud_identifier16_async_api(requires--features async)
Run them with:
for ex in examples/*.rs; do
name="$(basename "$ex" .rs)"
if [ "$name" = "16_async_api" ]; then
cargo run --example "$name" --features async
else
cargo run --example "$name"
fi
done§Verification
cargo clippy --all-features --all-targets -- -D warnings
cargo test --all-features
for ex in examples/*.rs; do
name="$(basename "$ex" .rs)"
if [ "$name" = "16_async_api" ]; then
cargo run --example "$name" --features async
else
cargo run --example "$name"
fi
done§License
Licensed under either of Apache-2.0 or MIT at your option.
Re-exports§
pub use asset::PHAsset;pub use asset::PHAssetBurstSelectionType;pub use asset::PHAssetEditOperation;pub use asset::PHAssetMediaSubtype;pub use asset::PHAssetPlaybackStyle;pub use asset::PHAssetResource;pub use asset::PHAssetResourceType;pub use asset::PHAssetSourceType;pub use asset::PHCoordinate;pub use asset::PHMediaType;pub use asset_change_request::PHAssetChangeRequest;pub use asset_collection::PHAssetCollection;pub use asset_collection::PHAssetCollectionSubtype;pub use asset_collection::PHAssetCollectionType;pub use asset_collection::PHCollectionEditOperation;pub use asset_collection_change_request::PHAssetCollectionAssetMutation;pub use asset_collection_change_request::PHAssetCollectionChangeRequest;pub use asset_creation_request::PHAssetCreationRequest;pub use asset_creation_request::PHAssetCreationResource;pub use asset_creation_request::PHAssetResourceCreationOptions;pub use asset_resource_manager::PHAssetResourceDataResult;pub use asset_resource_manager::PHAssetResourceManager;pub use asset_resource_manager::PHAssetResourceRequestOptions;pub use asset_resource_manager::PHAssetResourceWriteResult;pub use change::PHChange;pub use change_request::PHChangeRequest;pub use cloud_identifier::PHCloudIdentifier;pub use cloud_identifier::PHCloudIdentifierMapping;pub use cloud_identifier::PHLocalIdentifierMapping;pub use collection::PHCollection;pub use collection_list::PHCollectionList;pub use collection_list::PHCollectionListSubtype;pub use collection_list::PHCollectionListType;pub use collection_list_change_request::PHCollectionListChangeRequest;pub use collection_list_change_request::PHCollectionListChildMutation;pub use content_editing_controller::PHContentEditingController;pub use content_editing_controller::PHContentEditingPlaceholderImage;pub use content_editing_input::PHAdjustmentData;pub use content_editing_input::PHContentEditingInput;pub use content_editing_input::PHContentEditingInputInfo;pub use content_editing_input::PHContentEditingInputRequestOptions;pub use content_editing_output::PHContentEditingOutput;pub use content_editing_output::PHContentEditingOutputInfo;pub use error::NSErrorInfo;pub use error::PHAuthorizationStatus;pub use error::PHLocalIdentifiersErrorKey;pub use error::PHPhotosError;pub use error::PHPhotosErrorDomain;pub use error::PhotoKitError;pub use fetch_options::PHFetchOptions;pub use fetch_options::PHSortDescriptor;pub use fetch_result::PHFetchResult;pub use fetch_result_change_details::PHFetchResultChangeDetails;pub use fetch_result_change_details::PHFetchResultMove;pub use geometry::PHColor;pub use geometry::PHRect;pub use image_manager::PHCachingImageManager;pub use image_manager::PHImageContentMode;pub use image_manager::PHImageDataRequestHandle;pub use image_manager::PHImageDataResult;pub use image_manager::PHImageErrorKey;pub use image_manager::PHImageManager;pub use image_manager::PHImageManagerMaximumSize;pub use image_manager::PHImageRequest;pub use image_manager::PHImageRequestHandle;pub use image_manager::PHImageRequestOptionsDeliveryMode;pub use image_manager::PHImageRequestOptionsResizeMode;pub use image_manager::PHImageRequestOptionsVersion;pub use image_manager::PHImageResult;pub use image_manager::PHImageResultRequestIDKey;pub use image_manager::PHImageSize;pub use image_manager::PHLivePhotoRequestHandle;pub use image_manager::PHVideoRequestOptions;pub use image_manager::PHVideoRequestOptionsDeliveryMode;pub use image_manager::PHVideoRequestOptionsVersion;pub use image_manager::PHVideoResult;pub use live_photo::PHLivePhoto;pub use live_photo::PHLivePhotoInfoErrorKey;pub use live_photo::PHLivePhotoResult;pub use live_photo_editing_context::PHLivePhotoEditingContext;pub use live_photo_editing_context::PHLivePhotoEditingContextInfo;pub use live_photo_editing_context::PHLivePhotoEditingSaveResult;pub use live_photo_editing_context::PHLivePhotoFrame;pub use live_photo_editing_context::PHLivePhotoFrameProcessingDecision;pub use live_photo_editing_context::PHLivePhotoFrameType;pub use live_photo_view::PHLivePhotoView;pub use live_photo_view::PHLivePhotoViewContentMode;pub use live_photo_view::PHLivePhotoViewDelegate;pub use live_photo_view::PHLivePhotoViewDelegateEvent;pub use live_photo_view::PHLivePhotoViewDelegateEventKind;pub use live_photo_view::PHLivePhotoViewInfo;pub use live_photo_view::PHLivePhotoViewPlaybackStyle;pub use object::PHObject;pub use object::PHObjectPlaceholder;pub use object_change_details::PHObjectChangeDetails;pub use persistent_change::PHObjectType;pub use persistent_change::PHPersistentChange;pub use persistent_change::PHPersistentChangeFetchResult;pub use persistent_change::PHPersistentChangeToken;pub use persistent_change::PHPersistentObjectChangeDetails;pub use photo_library::PHAccessLevel;pub use photo_library::PHAvailabilityObserver;pub use photo_library::PHChangeObserver;pub use photo_library::PHPhotoLibrary;pub use photo_library::PHPhotoLibraryAvailabilityChange;pub use photo_library::PHPhotoLibraryChange;pub use picker::PHDirectionalRectEdge;pub use picker::PHItemProviderInfo;pub use picker::PHPickerCapabilities;pub use picker::PHPickerConfiguration;pub use picker::PHPickerConfigurationAssetRepresentationMode;pub use picker::PHPickerConfigurationSelection;pub use picker::PHPickerFilter;pub use picker::PHPickerMode;pub use picker::PHPickerResult;pub use picker::PHPickerUpdateConfiguration;pub use picker::PHPickerViewController;pub use picker::PHPickerViewControllerDelegate;pub use project::PHProject;pub use project::PHProjectChangeRequest;pub use project_extension::PHProjectExtensionContext;pub use project_extension::PHProjectExtensionController;pub use project_extension::PHProjectTypeDescription;pub use project_extension::PHProjectTypeDescriptionDataSource;pub use project_extension::PHProjectTypeDescriptionInvalidator;pub use project_info::PHProjectAssetElement;pub use project_info::PHProjectCreationSource;pub use project_info::PHProjectElement;pub use project_info::PHProjectInfo;pub use project_info::PHProjectJournalEntryElement;pub use project_info::PHProjectMapAnnotation;pub use project_info::PHProjectMapElement;pub use project_info::PHProjectRegionOfInterest;pub use project_info::PHProjectSection;pub use project_info::PHProjectSectionContent;pub use project_info::PHProjectSectionElement;pub use project_info::PHProjectSectionType;pub use project_info::PHProjectTextElement;pub use project_info::PHProjectTextElementType;
Modules§
- asset
- Wraps
PHAsset,PHAssetResource, and related Photos framework asset types. - asset_
change_ request - Wraps
PHAssetChangeRequestmutation APIs. - asset_
collection - Wraps
PHAssetCollectionand related Photos framework collection types. - asset_
collection_ change_ request - Wraps
PHAssetCollectionChangeRequestmutation APIs. - asset_
creation_ request - Wraps
PHAssetCreationRequestcreation APIs. - asset_
resource_ manager - Wraps
PHAssetResourceManager. - async_
api async - Async wrappers for Photos framework completion-handler APIs.
Async API for
photokit(Photos.framework) - change
- Wraps
PHChange. - change_
request - Traits for Photos framework change-request wrappers.
- cloud_
identifier - Wraps
PHCloudIdentifierand related Photos framework identifier mappings. - collection
- Wraps
PHCollection. - collection_
list - Wraps
PHCollectionListand related Photos framework list types. - collection_
list_ change_ request - Wraps
PHCollectionListChangeRequestmutation APIs. - content_
editing_ controller - Wraps the
PHContentEditingControllerprotocol contract. - content_
editing_ input - Wraps
PHContentEditingInputand related Photos framework editing-input types. - content_
editing_ output - Wraps
PHContentEditingOutputand related Photos framework editing-output types. - error
- Wraps Photos framework authorization and error values.
- fetch_
options - Wraps
PHFetchOptions. - fetch_
result - Wraps
PHFetchResult. - fetch_
result_ change_ details - Wraps
PHFetchResultChangeDetails. - geometry
- Shared geometry and color helper payloads used by PhotosUI wrappers.
- image_
manager - Wraps
PHImageManagerandPHCachingImageManager. - library
- Re-exports Photos framework wrapper types.
- live_
photo - Wraps
PHLivePhotoand related request results. - live_
photo_ editing_ context - Wraps
PHLivePhotoEditingContextand related frame-processing types. - live_
photo_ view - Wraps
PHLivePhotoViewand related PhotosUI playback callbacks. - object
- Wraps
PHObjectandPHObjectPlaceholder. - object_
change_ details - Wraps
PHObjectChangeDetails. - persistent_
change - Wraps persistent change history Photos framework types.
- photo_
library - Wraps
PHPhotoLibraryand observer registration APIs. - picker
- Wraps the
PHPickerfamily in PhotosUI. - prelude
- Common imports.
- project
- Wraps
PHProjectandPHProjectChangeRequest. - project_
extension - Wraps PhotosUI project-extension context and type-description helpers.
- project_
info - Wraps PhotosUI
PHProjectInfoand related immutable project-content types. - types
- Re-exports shared Photos framework wrapper types.