From 05a0be9a249cdadd137b0bc75e7355959a1ab8e8 Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 14 Oct 2024 03:37:30 +0800 Subject: [PATCH 1/5] add error text --- packages/sidan-csl-rs/src/core/utils/evaluator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sidan-csl-rs/src/core/utils/evaluator.rs b/packages/sidan-csl-rs/src/core/utils/evaluator.rs index 58ac895..741bb08 100644 --- a/packages/sidan-csl-rs/src/core/utils/evaluator.rs +++ b/packages/sidan-csl-rs/src/core/utils/evaluator.rs @@ -43,7 +43,7 @@ pub fn evaluate_tx_scripts_js( let deserialize_network = match serde_json::from_str(network.as_str()) { Ok(network) => network, Err(e) => { - return WasmResult::new_error("failure".to_string(), format!("{:?}", e)); + return WasmResult::new_error("failure".to_string(), format!("Error in decoding network: {:?}", e)); } }; From 44190b687676dec4d122c1ec727fff2d911ad582 Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 14 Oct 2024 03:37:55 +0800 Subject: [PATCH 2/5] network deserialization fix --- packages/sidan-csl-rs/src/core/utils/evaluator.rs | 4 ++-- .../src/model/tx_builder_types/network.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/sidan-csl-rs/src/core/utils/evaluator.rs b/packages/sidan-csl-rs/src/core/utils/evaluator.rs index 741bb08..470dd50 100644 --- a/packages/sidan-csl-rs/src/core/utils/evaluator.rs +++ b/packages/sidan-csl-rs/src/core/utils/evaluator.rs @@ -35,12 +35,12 @@ pub fn evaluate_tx_scripts_js( match serde_json::from_str(utxo_json.as_str()) { Ok(utxo) => deserialized_utxos.push(utxo), Err(e) => { - return WasmResult::new_error("failure".to_string(), format!("{:?}", e)); + return WasmResult::new_error("failure".to_string(), format!("Error in decoding UTXO: {:?}", e)); } } } - let deserialize_network = match serde_json::from_str(network.as_str()) { + let deserialize_network = match network.try_into() { Ok(network) => network, Err(e) => { return WasmResult::new_error("failure".to_string(), format!("Error in decoding network: {:?}", e)); diff --git a/packages/sidan-csl-rs/src/model/tx_builder_types/network.rs b/packages/sidan-csl-rs/src/model/tx_builder_types/network.rs index 2923107..a6becd2 100644 --- a/packages/sidan-csl-rs/src/model/tx_builder_types/network.rs +++ b/packages/sidan-csl-rs/src/model/tx_builder_types/network.rs @@ -8,3 +8,16 @@ pub enum Network { Preview, Custom(Vec>), } + +impl TryFrom for Network { + type Error = serde_json::Error; + + fn try_from(s: String) -> Result { + match s.to_lowercase().as_str() { + "mainnet" => Ok(Network::Mainnet), + "preprod" => Ok(Network::Preprod), + "preview" => Ok(Network::Preview), + _ => serde_json::from_str(&s), + } + } +} \ No newline at end of file From 3a47d4c49002a9090af1f30824f33f014f1cf457 Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 14 Oct 2024 04:12:16 +0800 Subject: [PATCH 3/5] add tests --- packages/sidan-csl-rs/src/core/utils/evaluator.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/sidan-csl-rs/src/core/utils/evaluator.rs b/packages/sidan-csl-rs/src/core/utils/evaluator.rs index 470dd50..5c02972 100644 --- a/packages/sidan-csl-rs/src/core/utils/evaluator.rs +++ b/packages/sidan-csl-rs/src/core/utils/evaluator.rs @@ -383,4 +383,19 @@ mod test { let script_ref = to_pallas_script_ref(&Some("82005655010000322223253330054a229309b2b1bad0025735".to_string())); assert!(script_ref.is_err()); } + + #[test] + fn test_network_type_decode() { + let network = Network::Mainnet; + let network_str = "Mainnet"; + let network_type: Network = network_str.to_string().try_into().unwrap(); + assert_eq!(network, network_type); + } + + #[test] + fn test_network_type_decode_error() { + let network_str = "Invalid"; + let network_type: Result = network_str.to_string().try_into(); + assert!(network_type.is_err()); + } } From 29a56618f3adb328e09a09858eec9ff1182316f5 Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 14 Oct 2024 15:43:50 +0800 Subject: [PATCH 4/5] add test --- .../sidan-csl-rs/src/core/utils/evaluator.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/sidan-csl-rs/src/core/utils/evaluator.rs b/packages/sidan-csl-rs/src/core/utils/evaluator.rs index 5c02972..d9734dc 100644 --- a/packages/sidan-csl-rs/src/core/utils/evaluator.rs +++ b/packages/sidan-csl-rs/src/core/utils/evaluator.rs @@ -398,4 +398,44 @@ mod test { let network_type: Result = network_str.to_string().try_into(); assert!(network_type.is_err()); } + + #[test] + fn test_utxo_tx_evaluating() { + let tx_hex = "84a900818258205de23a200f136e657307bc69173dddaf38b446bd7242a50f5bf255e329018b65030182a300581d70eafce55e4f0e057b495f77d8019577c56ae1fe188dc7e6d63f4f93b801821a001e8480a1581c32b7e3d552b2b18cb9bf1a39e6e1ce75f62c084f2b917a44c071a3bda14001028201d81858b4d8799f582461666461373264392d383039332d343330332d623030652d3233616362323934313432661a06acfc00d8799fd8799f581c5e0abc8c791c220b8c56e729cb77e95c03c7bd27971896dda0ac2368ffd8799fd8799fd8799f581cc8fdacb82c1cec476d444f559c28f4b75ddb6f483fe20427683a661affffffff1b0000019223dc5f75d8799fd8799f58205f759f3527a47632735470586a7ab2fbee4b4aa8b6504d52d52bc62fa8ec961aff00ff01ff825839005e0abc8c791c220b8c56e729cb77e95c03c7bd27971896dda0ac2368c8fdacb82c1cec476d444f559c28f4b75ddb6f483fe20427683a661a1a15a2ae54021a000d5ab0031a0442ee8109a1581c32b7e3d552b2b18cb9bf1a39e6e1ce75f62c084f2b917a44c071a3bda140010b5820c131e4b612c1a50ddcb739f58185148a26c6beaa198d036f5f9e4e8c7d458de20d8382582002345ff40e1b8730434571b8b4749ad084b2cd582aa8997fa7416be8b76c7da80082582002345ff40e1b8730434571b8b4749ad084b2cd582aa8997fa7416be8b76c7da8058258201c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a441020e81581cc6aa7af71f8ba577246149edf075d2edd9daa63980b7ca176799af6c128382582066b7282bad1aef9ba0a99f06e618d651d232d4788f0d2ee2d22db22a62391033008258205f759f3527a47632735470586a7ab2fbee4b4aa8b6504d52d52bc62fa8ec961a008258201c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a44100a10581840100d8799fd8799f58205f759f3527a47632735470586a7ab2fbee4b4aa8b6504d52d52bc62fa8ec961aff00ff820101f5f6"; + let utxo_1 = "{\"input\": {\"outputIndex\": 3, \"txHash\": \"5de23a200f136e657307bc69173dddaf38b446bd7242a50f5bf255e329018b65\"}, \"output\": {\"address\": \"addr_test1qrsaqj54nyedfg74tye8743tkrclgnfztj6z937g50q0fwv6vwcuvc9guftgju6xav470f6da9guk8t3nn46wd34z43s99hwxv\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"365858180\"}], \"scriptHash\": null}}"; + let utxo_2 = "{\"input\": {\"outputIndex\": 0, \"txHash\": \"02345ff40e1b8730434571b8b4749ad084b2cd582aa8997fa7416be8b76c7da8\"}, \"output\": {\"address\": \"addr_test1qrsaqj54nyedfg74tye8743tkrclgnfztj6z937g50q0fwv6vwcuvc9guftgju6xav470f6da9guk8t3nn46wd34z43s99hwxv\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"5000000\"}], \"scriptHash\": null}}"; + let utxo_3 = "{\"input\": {\"outputIndex\": 5, \"txHash\": \"02345ff40e1b8730434571b8b4749ad084b2cd582aa8997fa7416be8b76c7da8\"}, \"output\": {\"address\": \"addr_test1qrsaqj54nyedfg74tye8743tkrclgnfztj6z937g50q0fwv6vwcuvc9guftgju6xav470f6da9guk8t3nn46wd34z43s99hwxv\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"5000000\"}], \"scriptHash\": null}}"; + let utxo_4 = "{\"input\": {\"outputIndex\": 0, \"txHash\": \"1c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a441\"}, \"output\": {\"address\": \"addr_test1qrsaqj54nyedfg74tye8743tkrclgnfztj6z937g50q0fwv6vwcuvc9guftgju6xav470f6da9guk8t3nn46wd34z43s99hwxv\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"123000000\"}], \"scriptHash\": null}}"; + let utxo_5 = "{\"input\": {\"outputIndex\": 2, \"txHash\": \"1c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a441\"}, \"output\": {\"address\": \"addr_test1qrsaqj54nyedfg74tye8743tkrclgnfztj6z937g50q0fwv6vwcuvc9guftgju6xav470f6da9guk8t3nn46wd34z43s99hwxv\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"5000000\"}], \"scriptHash\": null}}"; + let utxo_6 = "{\"input\": {\"outputIndex\": 0, \"txHash\": \"66b7282bad1aef9ba0a99f06e618d651d232d4788f0d2ee2d22db22a62391033\"}, \"output\": {\"address\": \"addr_test1qp0q40yv0ywzyzuv2mnjnjmha9wq83aay7t339ka5zkzx6xglkktstqua3rk63z02kwz3a9hthdk7jplugzzw6p6vcdqa39gds\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"26000000\"}], \"scriptHash\": \"32b7e3d552b2b18cb9bf1a39e6e1ce75f62c084f2b917a44c071a3bd\", \"scriptRef\": \"8202590eca590ec701000033232323232323223223232322533300832323232323232323232323232323232323232323232323232323232323232323232323232323232325333031302d30323754002264a66606460540022a666064666018910103313333000063758601660686ea8c080c0d0dd50158a9998191998050031bac301130343754604060686ea80acdd61810181a1baa30203034375405626666444464646464a666074606c60766ea80044c8c8c8c8c8c8c94ccc10402854ccc10402454ccc10401854ccc10400c54ccc10400840045280a5014a0294052819192999821181f0008b0a999821181d000899b89375a608e60886ea8008dd6982398241824182418221baa0061630423754002605c60846ea8c114c118c108dd50059980f99baf301a30413754006605a60826ea8059240132496e74656e7420646174756d2073686f756c6420636f6e7461696e20616c6c206d61746368696e6720726566732075736564003301e3375e605860806ea8010c084c100dd50092493f496e74656e7420746f6b656e2073686f756c64206f6e6c7920657665722062652073656e7420746f20696e74656e74207370656e64696e672073637269707400533303d3039303e37540022646464646464646464646464a666098609e0042646493182280218178038b18268009826801182580098258011bad3049001304900230470013047002375a608a002608a0046086002607e6ea800458cc0640092401264f7574707574206d75737420636f6e7461696e20736f6d6520696e6c696e656420646174756d003301b3024301c323300100137566036607c6ea8008894ccc10000452f5c0264666444646600200200644a66608c0022006264660906e9ccc120dd4803198241822800998241823000a5eb80cc00c00cc128008c120004dd7181f8009bab304000133003003304400230420014901224f6e6c792061646120616c6c6f776564207769746820696e74656e7420746f6b656e00303f303c37540022ca6660780062980103d87a80001302d3303d303e0034bd701980c1818181380124812e4f6e6c7920612073696e676c65206f7574707574207769746820696e74656e7420746f6b656e20616c6c6f77656400330173375e6e98c04c00cdd31991299981c9818a4000297adef6c6013232330010014bd6f7b63011299981f80089982019bb0375200a6e9800d2f5bded8c0264646464a66608066e400240084cc110cdd81ba9009374c00e00a2a66608066e3c0240084cc110cdd81ba9009374c00e00626608866ec0dd48011ba600133006006003375660820066eb8c0fc008c10c008c104004c8cc0040052f5bded8c044a66607c00226607e66ec0dd4801a610101004bd6f7b630099191919299981f99b90007002133043337606ea401d3010101000051533303f3371e00e00426608666ec0dd4803a61010100003133043337606ea4008dd4000998030030019bad3040003375c607c004608400460800026eb8c094c0e4dd50029bae30163039375400a9212b4f6e6c7920612073696e676c6520696e74656e7420746f6b656e2073686f756c64206265206d696e74656400330280032302f3330153756602c60726ea8004dd71812981c9baa005375c602c60726ea8014c098cc0d8dd48021981b2610140004bd701bac301530343754604060686ea80acdd59806981a1baa302030343754056606e607060706070607060706070607060686ea8c080c0d0dd50158a5014a02a66606466e2000520001533303233300c488103313838000063758601660686ea8c080c0d0dd501589998050031bac301130343754604060686ea80acdd61810181a1baa302030343754056294058dd6981b18199baa00116533303030283301501500113301b0014890014c103d87a8000325333030302830313754002297adef6c6013756606a60646ea8004cc064c02cdd5980518189baa301d3031375405000264a66605e605660606ea80044dd7181a18189baa00116300d3030375404ea66605a6052605c6ea80044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc108c1140084c8c8c8c8c8c8c926302b00b302a00c302a00d302900e302700f303b010533303f303b3040375402226464a666088608e004264931981b000919181798228011bae3043001163756608a00260826ea80445858c10c004c10c008dd698208009820801181f800981f801181e800981e801181d800981d801181c800981c801181b800981b801181a800981a801181980098179baa00116300f302e3754004a666056604e60586ea80044c8c8c8c8c8c94ccc0d0c0dc0084c8c926301a00430190051630350013035002303300130330023031001302d37540022c6600e601260586ea800524011e436f6c642072656620646174756d206d75737420626520696e6c696e6564003232533302b323300100102a22533303000114a0264a66605c64604e66601a6eacc038c0c4dd5180718189baa005375c603a60626ea8004dd7180718189baa001303300214a2266006006002606600220022ca666054604c60566ea80044c0bcc0b0dd50008b198069bac3008302b3754602e60566ea8088098888c94ccc0b14ccc0b0c090c0b4dd519808001980598171baa0041614a2200229414ccc0acc09cc0b0dd519807800980518169baa0031614a24605a605c605c605c605c605c605c605c605c00244464660020026464a6660586050605a6ea80044c0c4c0b8dd50008992999816981498171baa00113032302f37540022c6603e00491010130003301e0010053756603060586ea8c060c0b0dd5001912999815981398161baa001132323300100100522533303100114a0264a66605e66e3cdd7181a0010020a511330030030013034001375c6060605a6ea80044c8cdc49bad30313032001301b3301e375860620024660080080026eb0c0c0c0b4dd5000918159816181618161816000919198008008011129998150008a5eb7bdb1804c8c8c8c94ccc0accdc8a45000021533302b3371e9101000021003100513302f337606ea4008dd3000998030030019bab302c003375c6054004605c00460580024464a66604c601e604e6ea80044c0acc0a0dd50008b180418139baa002222325333026301e302737540022900009bad302b3028375400264a66604c603c604e6ea8004530103d87a80001330113756605660506ea8004008cc03c00c0088c09cc0a0004894ccc0880085288b18008009129998118008a40002602266004004604c002460466048604800244646600200200644a666046002298103d87a80001323253330223375e602060486ea80080144c058cc0980092f5c0266008008002604e004604a00244a66604000229000098071980100118118009299980d980b980e1baa0011323232325333022302500213232498c94ccc084c0740044c8c94ccc098c0a40084c9263019001163027001302337540062a66604260320022a66604860466ea800c526161630213754004602c0062c604600260460046042002603a6ea80045894ccc068c058c06cdd5000899191919299981098120010a4c2c6eb8c088004c088008dd71810000980e1baa00116232533301a301600113232533301f3022002149858dd71810000980e1baa0021533301a301200113232533301f3022002132498c05c00458c080004c070dd50010a99980d180180089919299980f981100109924c60240022c604000260386ea800854ccc068cdc3a400c00226464a66603e60440042649319299980e980c800899192999811181280109924c602a0022c6046002603e6ea800854ccc074c0540044c8c94ccc088c0940084c9263015001163023001301f37540042a66603a600c002264646464a666048604e00426493180b8018b1bae302500130250023023001301f37540042a66603a66e1d200600113232323253330243027002149858dd7181280098128011bae3023001301f37540042a66603a66e1d200800113232323253330243027002149858dd6981280098128011bae3023001301f37540042a66603a66e1d200a00115333020301f37540042930b0a99980e99b874803000454ccc080c07cdd50010a4c2c2c603a6ea800458c080004c070dd50010b180d1baa001370e900211191980080080191299980e8008a60103d87a8000132323232533301e3372200e0042a66603c66e3c01c0084c048cc088dd3000a5eb80530103d87a80001330060060033756603e0066eb8c074008c084008c07c00488c8cc00400400c894ccc0700045300103d87a8000132323232533301d3372200e0042a66603a66e3c01c0084c044cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c00400488c94ccc058c0480044c8c94ccc06cc07800852616375c603800260306ea800854ccc058c0380044c8c94ccc06cc0780084c926323232533301e3021002132498cc04000c8cc02402400458dd6980f800980f8011bac301d001163758603800260306ea800858c058dd50009180c000980080091299980a8008a4000260066600400460300026e01200222323300100100322533301500114bd7009919299980a180280109980c00119802002000899802002000980c801180b80091191980080080191299980a0008a6103d87a800013232323253330153372200e0042a66602a66e3c01c0084c024cc0640052f5c0298103d87a80001330060060033016003375c60280046030004602c0026e95200022323300100100322533301200114984c8cc00c00cc058008c00cc0500048c94ccc030c0200044c8c94ccc044c0500084c9263005001163012001300e37540042a66601860080022646464646464a66602a60300042930b1bad30160013016002375a602800260280046eb4c048004c038dd50010b18061baa001232533300b30070011323253330103013002149858dd7180880098069baa0021533300b30030011323253330103013002149858dd7180880098069baa00216300b37540026e1d200214984d958c00400c94ccc018c008c01cdd50008991919192999806980800109924ca666014600c60166ea800c4c8c94ccc03cc04800852616375c602000260186ea800c5858dd698070009807001180600098041baa00116370e90001bac0015734aae7555cf2ab9f5740ae855d12601259fd8799f581c55871db8a58f10fddf48b92029827d168271e785646af257de85486c40ffff0001\"}}"; + let utxo_7 = "{\"input\": {\"outputIndex\": 0, \"txHash\": \"5f759f3527a47632735470586a7ab2fbee4b4aa8b6504d52d52bc62fa8ec961a\"}, \"output\": {\"address\": \"addr_test1qp0q40yv0ywzyzuv2mnjnjmha9wq83aay7t339ka5zkzx6xglkktstqua3rk63z02kwz3a9hthdk7jplugzzw6p6vcdqa39gds\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"4000000\"}, {\"unit\": \"55871db8a58f10fddf48b92029827d168271e785646af257de85486c\", \"quantity\": \"1\"}], \"dataHash\": \"a5a21bf7d9119e01f8cf04316dba1d9cdcacd998430728fdb938de8dad4b6c1f\", \"plutusData\": \"d8799fd8799f581c0eb1e4ef980b3c308edd7b3ab64990d5240e5230286038cae5c634cdffd8799f581c1fdf3668220c08618b4f2e5e7cc54f70ca4b11fd2b6a3fbe678235f1ffd8799fd8799fa14130d8799f581cc6aa7af71f8ba577246149edf075d2edd9daa63980b7ca176799af6cffffd8799fd8799f58201c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a441ff00ffd8799fd87a9f581ceafce55e4f0e057b495f77d8019577c56ae1fe188dc7e6d63f4f93b8ffd87a80ffd8799f581c32b7e3d552b2b18cb9bf1a39e6e1ce75f62c084f2b917a44c071a3bd40ffd8799f581cdbde35dec305604c1c8a596437802fd5e3468c8e92ce1781203e7bb74455534441ffd8799fd87a9f581c10fcea52f80dbc6e499106b02894173a2e60d21c6b3d1fe881d9495dffd87a80ffd8799fd8799f581cc6aa7af71f8ba577246149edf075d2edd9daa63980b7ca176799af6cffd87a80ff1903e801ffff\", \"scriptHash\": null}}"; + let mut resolved_utxos = JsVecString::new(); + resolved_utxos.add(utxo_1.to_string()); + resolved_utxos.add(utxo_2.to_string()); + resolved_utxos.add(utxo_3.to_string()); + resolved_utxos.add(utxo_4.to_string()); + resolved_utxos.add(utxo_5.to_string()); + resolved_utxos.add(utxo_6.to_string()); + resolved_utxos.add(utxo_7.to_string()); + + let additional_txs = JsVecString::new(); + + let result = evaluate_tx_scripts_js( + tx_hex.to_string(), + resolved_utxos, + additional_txs, + "preprod".to_string() + ); + + assert_eq!(result.get_status(), "success"); + + let actions: Vec = serde_json::from_str(&result.get_data()).unwrap(); + assert_eq!(actions.len(), 1); + + let action = &actions[0]; + assert_eq!(action.budget.mem, 508703); + assert_eq!(action.budget.steps, 164980381); + assert_eq!(action.tag, RedeemerTag::Mint); + assert_eq!(action.index, 0); + } } From 0980b2646607eb72095955a0464a125b29a858a2 Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 14 Oct 2024 16:00:22 +0800 Subject: [PATCH 5/5] pass by ref --- packages/sidan-csl-rs/src/core/utils/evaluator.rs | 10 +++++----- packages/sidan-csl-rs/src/model/js_vec.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/sidan-csl-rs/src/core/utils/evaluator.rs b/packages/sidan-csl-rs/src/core/utils/evaluator.rs index d9734dc..881c317 100644 --- a/packages/sidan-csl-rs/src/core/utils/evaluator.rs +++ b/packages/sidan-csl-rs/src/core/utils/evaluator.rs @@ -26,8 +26,8 @@ use uplc::{ #[wasm_bindgen] pub fn evaluate_tx_scripts_js( tx_hex: String, - resolved_utxos: JsVecString, - additional_txs: JsVecString, + resolved_utxos: &JsVecString, + additional_txs: &JsVecString, network: String, ) -> WasmResult { let mut deserialized_utxos: Vec = Vec::new(); @@ -50,7 +50,7 @@ pub fn evaluate_tx_scripts_js( let eval_result = evaluate_tx_scripts( &tx_hex, &deserialized_utxos, - &additional_txs.into_vec(), + &additional_txs.as_ref_vec(), &deserialize_network, ); @@ -422,8 +422,8 @@ mod test { let result = evaluate_tx_scripts_js( tx_hex.to_string(), - resolved_utxos, - additional_txs, + &resolved_utxos, + &additional_txs, "preprod".to_string() ); diff --git a/packages/sidan-csl-rs/src/model/js_vec.rs b/packages/sidan-csl-rs/src/model/js_vec.rs index c66c9e5..c80bdfb 100644 --- a/packages/sidan-csl-rs/src/model/js_vec.rs +++ b/packages/sidan-csl-rs/src/model/js_vec.rs @@ -30,6 +30,10 @@ impl JsVecString { pub(crate) fn into_vec(self) -> Vec { self.0 } + + pub(crate) fn as_ref_vec(&self) -> &Vec { + &self.0 + } } impl IntoIterator for JsVecString { @@ -41,6 +45,15 @@ impl IntoIterator for JsVecString { } } +impl<'a> IntoIterator for &'a JsVecString { + type Item = &'a String; + type IntoIter = std::slice::Iter<'a, String>; + + fn into_iter(self) -> Self::IntoIter { + self.0.iter() + } +} + impl JsVecString { pub fn iter(&self) -> std::slice::Iter { self.0.iter()