pass in full scramjet config

This commit is contained in:
Toshit Chawda 2024-07-29 22:29:32 -07:00
parent c60645d478
commit f0e8aed666
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
2 changed files with 10 additions and 12 deletions

View file

@ -33,7 +33,11 @@ fn create_encode_function(encode: JsValue) -> EncodeFn {
})
}
fn get_str(config: &Object, k: &str) -> String {
fn get_obj(config: &JsValue, k: &str) -> JsValue {
Reflect::get(config, &k.into()).unwrap()
}
fn get_str(config: &JsValue, k: &str) -> String {
Reflect::get(config, &k.into())
.unwrap()
.as_string()
@ -43,7 +47,7 @@ fn get_str(config: &Object, k: &str) -> String {
fn get_config(config: Object) -> Config {
Config {
prefix: get_str(&config, "prefix"),
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap()),
encode: create_encode_function(get_obj(&get_obj(&config, "codec"), "encode")),
wrapfn: get_str(&config, "wrapfn"),
importfn: get_str(&config, "importfn"),
rewritefn: get_str(&config, "rewritefn"),