unity_asset/lib.rs
1//! Unity Asset Parser
2//!
3//! A comprehensive Rust library for parsing Unity asset files, supporting both YAML and binary formats.
4//!
5//! This crate provides high-performance, memory-safe parsing of Unity files
6//! while aiming for best-effort compatibility with Unity's formats (correctness and coverage are ongoing work).
7//!
8//! # Features
9//!
10//! - **YAML Processing**: Complete Unity YAML format support with multi-document parsing
11//! - **Binary Assets**: AssetBundle and SerializedFile parsing with compression support
12//! - **Async Support**: Optional async/await API for concurrent processing (enable with `async` feature)
13//! - **Type Safety**: Rust's type system prevents common parsing vulnerabilities
14//! - **Performance**: Designed for reasonable performance; some workflows may be eager by default
15//!
16//! # Examples
17//!
18//! ## Basic YAML Processing
19//!
20//! ```rust,no_run
21//! use unity_asset::{YamlDocument, UnityDocument};
22//!
23//! // Load a Unity YAML file
24//! let doc = YamlDocument::load_yaml("ProjectSettings.asset", false)?;
25//!
26//! // Access and filter objects
27//! let settings = doc.get(Some("PlayerSettings"), None)?;
28//! println!("Product name: {:?}", settings.get("productName"));
29//!
30//! # Ok::<(), unity_asset::UnityAssetError>(())
31//! ```
32//!
33//! ## Binary Asset Processing
34//!
35//! ```rust,no_run
36//! use unity_asset::load_bundle_from_memory;
37//!
38//! // Load and parse AssetBundle
39//! let data = std::fs::read("game.bundle")?;
40//! let bundle = load_bundle_from_memory(data)?;
41//!
42//! // Process assets
43//! for asset in &bundle.assets {
44//! println!("Found asset with {} objects", asset.object_count());
45//! }
46//!
47//! # Ok::<(), Box<dyn std::error::Error>>(())
48//! ```
49//!
50//! ## Async Processing (requires `async` feature)
51//!
52//! ```rust,no_run
53//! # #[cfg(feature = "async")]
54//! # {
55//! use unity_asset::{YamlDocument, AsyncUnityDocument};
56//!
57//! #[tokio::main]
58//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
59//! // Load file asynchronously
60//! let doc = YamlDocument::load_yaml_async("ProjectSettings.asset", false).await?;
61//!
62//! // Same API as sync version
63//! let settings = doc.get(Some("PlayerSettings"), None)?;
64//! println!("Product name: {:?}", settings.get("productName"));
65//!
66//! Ok(())
67//! }
68//! # }
69//! ```
70
71// Re-export from core crate
72pub use unity_asset_core::{
73 DocumentFormat, Result, UnityAssetError, UnityClass, UnityClassRegistry, UnityDocument,
74 UnityValue, constants::*,
75};
76
77pub use unity_asset_core::get_class_name;
78pub use unity_asset_core::get_class_name_str;
79
80// Re-export from YAML crate
81pub use unity_asset_yaml::YamlDocument;
82
83// Re-export from binary crate
84pub use unity_asset_binary::asset::SerializedFile;
85pub use unity_asset_binary::bundle::{
86 AssetBundle, load_bundle, load_bundle_from_memory, load_bundle_with_options,
87};
88
89// Re-export async traits when async feature is enabled
90#[cfg(feature = "async")]
91pub use unity_asset_core::document::AsyncUnityDocument;
92
93/// Environment for managing multiple Unity assets
94pub mod environment;