easy_ml/web_assembly.rs
1/*!
2# Web Assembly examples
3
4## Example of creating an infinite iterator when targeting web assembly
5
6Because Easy ML uses randomness only via the calling code providing a source of random numbers,
7you can easily swap out the source of the randomness when targeting more restrictive environments.
8
9Random numbers can be obtained from the JavaScript `Math.random()` method which
10already has bindings to Rust provided by the [js-sys](https://crates.io/crates/js-sys) crate.
11
12```
13struct EndlessRandomGenerator {}
14
15impl Iterator for EndlessRandomGenerator {
16 type Item = f64;
17
18 fn next(&mut self) -> Option<Self::Item> {
19 Some(js_sys::Math::random())
20 }
21}
22```
23
24## Handwritten Digit Recognition on the MNIST dataset
25
26[Easy ML is used in an example for training a neural network to do handwritten digit recognition
27here](https://github.com/Skeletonxf/easy-ml-mnist-wasm-example).
28 */