Skip to main content

sb3_decoder/
lib.rs

1//! # sb3-decoder
2//! A Rust crate that decodes Scratch 3.0 project files (.sb3) into rust structs and enums.
3//!
4//! # Example
5//! ```no_run
6//! use sb3_decoder::prelude::*;
7//!
8//! let mut decoder = {
9//!     let decoder = Decoder::from_file("project.sb3"); // Read from a file
10//!     # /* rust wouldn't be able to find project.sb3, so this part is commented out
11//!     let decoder = Decoder::from_bytes(include_bytes!("project.sb3")); // Or load from memory
12//!     # */
13//!     decoder.expect("project should be valid")
14//! };
15//!
16//! // Decode the project
17//! let project = decoder.decode().expect("project should be valid");
18//!
19//! // Now let's print every hat and action block we find inside the Cat sprite
20//! let cat = project
21//!     .sprites
22//!     .iter()
23//!     .find(|sprite| sprite.name == "Cat")
24//!     .expect("there should be a Cat sprite");
25//! for script in &cat.scripts {
26//!     println!("{:?}", script.hat);
27//!     for action in &script.actions {
28//!         println!("{action:?}");
29//!     }
30//! }
31//! ```
32//!
33//! # Feature flags
34//! The features `costumes` and `sounds` are enabled by default.
35//!
36//! - `costumes` - costume decoding support, using image and resvg.
37//! - `sounds` - sound decoding support, using hound and nanomp3.
38
39pub mod decode;
40pub mod error;
41pub(crate) mod macros;
42pub mod model;
43pub mod prelude;
44pub(crate) mod raw;
45
46pub use error::Error;
47
48#[cfg(test)]
49mod tests {
50    mod decode_projects;
51    mod raw_deserialization;
52}