11use wasm_bindgen:: prelude:: * ;
22use web_sys:: console;
33
4-
54// When the `wee_alloc` feature is enabled, this uses `wee_alloc` as the global
65// allocator.
76//
@@ -10,10 +9,9 @@ use web_sys::console;
109#[ global_allocator]
1110static ALLOC : wee_alloc:: WeeAlloc = wee_alloc:: WeeAlloc :: INIT ;
1211
13- static mut ENABLED : & str = "strange_string" ;
14- static arr: [ i32 ; 5 ] = [ 1 , 2 , 3 , 4 , 5 ] ;
15- static arr2: [ & str ; 1 ] = [ "dupa" ] ;
12+ static mut ENABLED : bool = false ;
1613
14+ mod aes_test;
1715// This is like the `main` function, except for JavaScript.
1816// This is executed on import (at least with current setup :v )
1917#[ wasm_bindgen( start) ]
@@ -25,65 +23,27 @@ pub fn main_js() -> Result<(), JsValue> {
2523
2624 unsafe {
2725 // mock of license check on module load
28- ENABLED = "yes" ;
26+ ENABLED = aes_test :: aes_test ( ) ;
2927 }
3028
31- // Your code goes here!
32- // console::log_1(&JsValue::from_str("Hello world!"));
33-
3429 Ok ( ( ) )
3530}
3631
37- #[ wasm_bindgen]
38- pub fn enable ( query : String ) -> Result < ( ) , JsValue > {
39- unsafe {
40- ENABLED = "yes" ;
41- }
42- Ok ( ( ) )
43- }
32+ use js_sys;
4433
4534#[ wasm_bindgen]
46- pub fn get_str ( query : String ) -> Result < String , JsValue > {
47- let res: String = "res: " . to_owned ( ) ;
48- let space: String = String :: from ( " " ) ;
35+ pub fn trim_value ( obj : & JsValue ) -> Result < ( ) , JsValue > {
4936 unsafe {
50- // output = &(res + space + enabled + space + &query);
51- Ok ( res + & space + ENABLED + & space + & query + arr2[ 0 ] + & arr[ 4 ] . to_string ( ) )
37+ assert_eq ! ( ENABLED , true ) ;
5238 }
53- }
54-
55- use serde:: { Serialize , Deserialize } ;
56-
57- #[ derive( Serialize , Deserialize ) ]
58- struct Data {
59- pub key : String
60- }
61-
62- #[ wasm_bindgen]
63- pub fn get_field ( obj : & JsValue ) -> Result < String , JsValue > {
64- let example: Data = obj. into_serde ( ) . unwrap ( ) ;
65- Ok ( example. key )
66- }
67-
68- use js_sys;
69-
70- #[ wasm_bindgen]
71- pub fn set_field ( obj : & JsValue ) -> Result < ( ) , JsValue > {
72- js_sys:: Reflect :: set ( & obj, & JsValue :: from_str ( "key" ) , & JsValue :: from_str ( "dupa" ) ) ?;
73-
74- Ok ( ( ) )
75- }
76-
77- #[ wasm_bindgen]
78- pub fn transform_value ( obj : & JsValue ) -> Result < ( ) , JsValue > {
7939 let value = js_sys:: Reflect :: get ( & obj, & JsValue :: from_str ( "value" ) ) ?;
80- let to_trim: String = value. into_serde ( ) . unwrap ( ) ;
40+ let to_trim: String = value. into_serde ( ) . unwrap ( ) ;
8141 let trimmed = to_trim. trim ( ) ;
8242
83- js_sys:: Reflect :: set ( & obj , & JsValue :: from_str ( "value" ) , & JsValue :: from_str ( & trimmed ) ) ? ;
84- // console::log_1(&JsValue::from_str(&format!("Trimmed: {} -> {}", to_trim, trimmed)));
85- unsafe {
86- assert_eq ! ( ENABLED , "yes" ) ;
87- }
43+ js_sys:: Reflect :: set (
44+ & obj ,
45+ & JsValue :: from_str ( "value" ) ,
46+ & JsValue :: from_str ( & trimmed ) ,
47+ ) ? ;
8848 Ok ( ( ) )
89- }
49+ }
0 commit comments