File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -8,19 +8,25 @@ wit_bindgen::generate!({
88 }"
99} ) ;
1010
11- const IS_INITIALIZED : Cell < bool > = Cell :: new ( false ) ;
11+ // rustc won't allow using a a Cell in a static, but since this is a component (which is always
12+ // single-threaded) we can ignore this and mark it send and sync.
13+ struct MakeSendSync < T > ( T ) ;
14+ unsafe impl < T > Send for MakeSendSync < T > { }
15+ unsafe impl < T > Sync for MakeSendSync < T > { }
16+
17+ static IS_INITIALIZED : MakeSendSync < Cell < bool > > = MakeSendSync ( Cell :: new ( false ) ) ;
1218
1319struct S ;
1420impl Guest for S {
1521 fn component_init ( ) {
16- let before = IS_INITIALIZED . replace ( true ) ;
22+ let before = IS_INITIALIZED . 0 . replace ( true ) ;
1723 assert ! ( !before, "component should only be initialized once" ) ;
1824 }
1925}
2026
2127export ! ( S ) ;
2228
2329fn main ( ) {
24- let initialized = IS_INITIALIZED . get ( ) ;
30+ let initialized = IS_INITIALIZED . 0 . get ( ) ;
2531 assert ! ( initialized, "component was not initialized" )
2632}
Original file line number Diff line number Diff line change @@ -84,12 +84,9 @@ async fn init_rust() -> Result<()> {
8484
8585 let initialized_component = component_init_wasmtime:: initialize ( & component) . await ?;
8686
87- /*
88- // TODO: execute `component`. it should not trap.
8987 execute ( & initialized_component)
9088 . await
9189 . context ( "execute initialized component" ) ?;
92- */
9390
9491 Ok ( ( ) )
9592}
You can’t perform that action at this time.
0 commit comments