You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/writing-reactors/preambles.mdx
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -440,6 +440,80 @@ The important takeaway here is with the package.json file and the compiled JavaS
440
440
441
441
<ShowIfrs>
442
442
443
+
For example, the follow reactor brings the constant `PI` into scope allowing us to call `f64::const::PI` as `PI`
444
+
445
+
```lf-c
446
+
target Rust;
447
+
448
+
main reactor {
449
+
preamble {=
450
+
use std::f64::const::PI;
451
+
=}
452
+
453
+
reaction(startup) {=
454
+
println!("{}", PI);
455
+
=}
456
+
}
457
+
```
458
+
459
+
This will print:
460
+
461
+
```
462
+
3.141592653589793
463
+
```
464
+
for this example, we add the crate [hello](https://docs.rs/hello/latest/hello/) through the rust [cargo-dependencies](<../reference/target-declaration#cargo-dependencies>) target option.
465
+
```lf-C
466
+
target Rust {
467
+
cargo-dependencies: {
468
+
hello: "1.0.4",
469
+
},
470
+
};
471
+
472
+
preamble {=
473
+
use hello;
474
+
=}
475
+
476
+
main reactor {
477
+
reaction(startup) {
478
+
hello::world();
479
+
}
480
+
}
481
+
482
+
```
483
+
This will print:
484
+
```
485
+
Hello, world!
486
+
```
487
+
488
+
In this example we create a function `add_42` and a rust macro `add!`
0 commit comments