wasm_slim/lib.rs
1#![warn(missing_docs)]
2#![warn(clippy::unwrap_used)]
3#![cfg_attr(test, allow(clippy::unwrap_used))]
4
5//! wasm-slim library
6//!
7//! This library provides the core functionality for WASM bundle size optimization.
8//! It can be used programmatically in addition to the CLI interface.
9//!
10//! # Basic Example
11//!
12//! Creating and validating configuration:
13//!
14//! ```
15//! use wasm_slim::config::file::{ConfigFile, ProfileSettings};
16//!
17//! // Create configuration with custom profile settings
18//! let config = ConfigFile {
19//! template: "balanced".to_string(),
20//! profile: Some(ProfileSettings {
21//! opt_level: Some("z".to_string()),
22//! lto: Some("thin".to_string()),
23//! strip: Some(true),
24//! codegen_units: Some(1),
25//! panic: Some("abort".to_string()),
26//! }),
27//! wasm_opt: None,
28//! size_budget: None,
29//! };
30//!
31//! assert_eq!(config.template, "balanced");
32//! ```
33//!
34//! # Advanced Example: Size Budget Validation
35//!
36//! Using size budgets to enforce WASM bundle size limits:
37//!
38//! ```
39//! use wasm_slim::config::file::SizeBudget;
40//!
41//! // Create a size budget with target and thresholds
42//! let budget = SizeBudget {
43//! target_size_kb: Some(300),
44//! warn_threshold_kb: Some(400),
45//! max_size_kb: Some(500),
46//! };
47//!
48//! // Validate budget constraints
49//! let validation = budget.validate();
50//! assert!(validation.is_ok());
51//!
52//! // Invalid budget (target > max) should fail
53//! let bad_budget = SizeBudget {
54//! target_size_kb: Some(600),
55//! warn_threshold_kb: Some(400),
56//! max_size_kb: Some(500),
57//! };
58//! assert!(bad_budget.validate().is_err());
59//! ```
60//!
61//! # Advanced Example: Multi-stage Workflow
62//!
63//! Creating backups before modification:
64//!
65//! ```
66//! use wasm_slim::optimizer::BackupManager;
67//! use wasm_slim::config::file::ConfigFile;
68//! use std::path::Path;
69//! use tempfile::TempDir;
70//! use std::fs;
71//!
72//! // Setup temporary workspace
73//! let workspace = TempDir::new().unwrap();
74//! let cargo_toml = workspace.path().join("Cargo.toml");
75//! fs::write(&cargo_toml, "[package]\nname = \"test\"\n").unwrap();
76//!
77//! // Create backup before modification
78//! let backup_mgr = BackupManager::new(workspace.path());
79//! let backup_path = backup_mgr.create_backup(&cargo_toml).unwrap();
80//! assert!(backup_path.exists());
81//!
82//! // Backup contains original content
83//! let backup_content = fs::read_to_string(&backup_path).unwrap();
84//! assert!(backup_content.contains("test"));
85//!
86//! // Now safe to modify the original file
87//! let config = ConfigFile::default();
88//! fs::write(&cargo_toml, "[package]\nname = \"optimized\"\n").unwrap();
89//! ```
90
91/// Analysis tools for WASM bundles
92pub mod analyzer;
93/// Performance tracking utilities
94pub mod bench_tracker;
95/// CI/CD integration tooling
96pub mod cicd;
97/// Command handlers for CLI operations
98pub mod cmd;
99/// Configuration file and template management
100pub mod config;
101/// Enhanced error types with contextual suggestions
102pub mod error;
103/// Shared formatting utilities
104pub mod fmt;
105/// Git metadata utilities
106pub mod git;
107/// Infrastructure traits for filesystem and command execution
108pub mod infra;
109/// Cargo.toml optimization and backup management
110pub mod optimizer;
111/// Build pipeline orchestration
112pub mod pipeline;
113/// Rust toolchain detection and management
114pub mod toolchain;
115/// Tool detection and version checking
116pub mod tools;