Refactor model loading and add WASM support #40
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Overview
Refactored model loading functionality and added WASM environment support.
Key improvement: Changed
load_modelsignature from accepting&Pathto&str, enabling URI-based model loading with support forhttp://,https://, andfile://schemes. This makes the API more flexible and enables remote model loading from web servers.Additional improvements include reduced code duplication, improved error handling, and full WASM environment compatibility for HTTP/HTTPS-based model loading.
Main Changes
1. Model Loading Refactoring
parse_model_contenthelper method to eliminate code duplication betweenload_model_from_fileandload_model_from_url(approximately 33% code reduction)unwrap()calls with proper error propagation (?operator,map_err), and added detailed error messages with line numbersformat!("{}", e)toe.to_string()std::io::Error::new(ErrorKind::Other, ...)tostd::io::Error::other(...)2. WASM Environment Support
cfg(target_arch = "wasm32")rayon,tokio,tempfile, andtokio-testfrom WASM builds3. Code Organization Improvements
ModelSchemeenum: Moved fromadaboost.rstoutil.rsto clarify module responsibilitiestime,sync, andio-utilfeatures, keeping only the necessaryrt-multi-threadandmacros4. Test and Documentation Fixes
tokio_test::block_on)tokio-testto dev-dependenciesWASM Environment Behavior
✅ Supported Features
https://URLshttp://URLs❌ Unsupported Features (returns appropriate error messages)
file://schemeWhen loading models from different origins in WASM environments (browsers), CORS headers must be configured on the server side:
Note: This restriction is a browser security specification and cannot be circumvented on the client side (Litsea).