unity_asset_binary/
lib.rs

1//! Unity Binary Asset Parser
2//!
3//! This crate provides functionality to parse Unity binary file formats including:
4//! - AssetBundle files (.bundle, .unity3d)
5//! - Serialized Asset files (.assets)
6//! - Resource files
7//!
8//! # Features
9//!
10//! - **AssetBundle parsing**: Support for UnityFS format
11//! - **Compression support**: LZ4, LZMA, and other compression formats
12//! - **TypeTree parsing**: Dynamic type information for objects
13//! - **Object extraction**: Extract Unity objects from binary data
14//!
15//! ## Feature Flags
16//!
17//! This crate is intentionally **parser-only**.
18//! For decoding/export helpers (Texture/Audio/Sprite/Mesh), use the `unity-asset-decode` crate.
19//!
20//! # Example
21//!
22//! ```rust,no_run
23//! use unity_asset_binary::bundle::load_bundle_from_memory;
24//! use std::fs;
25//!
26//! // Load an AssetBundle file
27//! let data = fs::read("example.bundle")?;
28//! let bundle = load_bundle_from_memory(data)?;
29//!
30//! // Access contained assets
31//! for asset in &bundle.assets {
32//!     println!("Asset with {} objects", asset.object_count());
33//!     // Access objects in the asset
34//!     for object in &asset.objects {
35//!         println!("  Object: {} (type_id: {})", object.path_id, object.type_id);
36//!     }
37//! }
38//! # Ok::<(), Box<dyn std::error::Error>>(())
39//! ```
40
41// Core modules (always available)
42pub mod asset;
43pub mod bundle;
44pub mod compression;
45pub mod data_view;
46pub mod error;
47pub mod file;
48pub mod formats;
49pub mod metadata;
50pub mod object;
51pub mod performance;
52pub mod reader;
53pub mod shared_bytes;
54pub mod typetree;
55pub mod unity_objects;
56pub mod unity_version;
57pub mod webfile;
58
59pub use error::{BinaryError, Result};
60
61// Intentionally avoid massive top-level re-exports.
62//
63// Prefer importing from:
64// - `unity_asset_binary::formats::{bundle, serialized, web}`
65// - `unity_asset_binary::{bundle, asset, webfile, object, typetree, ...}`
66// - `unity_asset_binary::file::{load_unity_file, load_unity_file_from_memory}`
67
68#[cfg(test)]
69mod tests {
70    #[test]
71    fn test_basic_functionality() {
72        // Basic smoke test
73        assert_eq!(2 + 2, 4);
74    }
75
76    #[cfg(feature = "async")]
77    #[tokio::test]
78    async fn test_async_functionality() {
79        // Test that async features compile
80        let dummy_data = [0u8; 32];
81
82        // Test basic async functionality - for now just verify the feature compiles
83        // TODO: Implement actual async methods when needed
84        let _result = tokio::task::yield_now().await;
85
86        // Note: AssetBundle::from_bytes_async and SerializedFile::from_bytes_async
87        // are not yet implemented. They would be added when async support is needed.
88        assert!(!dummy_data.is_empty());
89    }
90}