Skip to content

Commit

Permalink
feat: to js err fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Aug 4, 2023
1 parent 6d77161 commit fdc33e7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use std::error::Error;

use astc_decode::{astc_decode, Footprint};
use lz4_flex::decompress;
use wasm_bindgen::prelude::*;

fn to_js_err(e: impl Error) -> JsError {
JsError::new(&e.to_string())
}

#[wasm_bindgen(js_name = decodeAstc)]
pub fn decode_astc(
data: &[u8],
Expand All @@ -23,11 +29,11 @@ pub fn decode_astc(

match astc_result {
Ok(()) => Ok(result),
Err(e) => Err(JsError::new(&e.to_string())),
Err(e) => Err(to_js_err(e)),
}
}

#[wasm_bindgen(js_name = decompressLz4)]
pub fn decompress_lz4(data: &[u8], size: usize) -> Result<Vec<u8>, JsError> {
decompress(data, size).map_err(|e| JsError::new(&e.to_string()))
decompress(data, size).map_err(to_js_err)
}

0 comments on commit fdc33e7

Please sign in to comment.