RegEx and other common crates in rust-based functions

Is there still no way to use RegEx in rust-based checkout validation functions?
When I try to simply use regex::Regex; my resulting WASM size would jump from 211 to 991 KB thus making the deployment impossible.
And if I try to use wasm_bindgen::prelude::*; use js_sys::RegExp; the compilation and deployment succeed, but at runtime, I get this error:

thread ‘’ panicked at …\index.crates.io-6f17d22bba15001f\js-sys-0.3.77\src\lib.rs:3960:1: cannot call wasm-bindgen imported functions on non-wasm targets

Am I understanding this correctly? Unlike JavaScript/TypeScript, where I have access to various text processing tools (including eval()), Rust doesn’t allow me to use anything more advanced than serde_json within the current constraints?
Or am I missing something?

Hi @eugals

Have you tried the regex_lite crate?

See this and other recommendations here:

-Nick

Thanks @NickWesselman!

I hadn’t noticed the mention of rust_lite in that guide.
Replacing the standard regex crate with rust_lite reduces the WASM size to just 306 KB! And if I run wasm-snip --snip-rust-panicking-code, it drops to around 285 KB — much better.

Unfortunately, wasm-opt fails to run on my code (regardless of whether wasm-snip is used) with this error:

[parse exception: Section extends beyond end of input (at 0:553)]

That said, to be honest, the regex crate wasn’t my main concern.
What I really need is something like rhai, but it blows up the size of the wasm-snipped WASM function to 1.4 MB.

Historically, our app has allowed users to write simple formulas in validation error templates — something like {{item.product_title}} or {{Math.round(CartWeight * 10) / 10}}, which gets evaluated and shown to the customer based on their cart contents.

This works perfectly fine as a theme extension script or in the JS-based cart validation function — and that version of the function.wasm is only 32,084 bytes!

But when I tried to offer the same level of flexibility using a more optimized language, I ran into the WASM size limitation — which is a major bummer for us. I’m really hoping someone can suggest a better approach to handle this.