Allows to try rust in Jupyter notebook. Implemented via line/cell magics:
-
Install rust and jupyter-notebook
-
cargo install cargo-script
-
pip install rust-magic
-
Enjoy :)
are supported via normal cargo script
syntax (see below for a more compact notation):
can be provided in the cell mode:
NB Here's a copy-pastable form of all the examples above.
To enable rust syntax highlighting in %%rust cells run the following snippet in a python jupyter cell:
from notebook.services.config import ConfigManager
c = ConfigManager()
c.update('notebook', {"CodeCell": {"highlight_modes": {"text/x-rustsrc": {"reg": ["^%%rust"]}}}})
This only needs to be run once: it stores the setting in a config file in home directory.
Jupyter "doesn't like" long cells: when a cell gets longer than the screen its output is not readily visible. Here're a few ways how to handle the problem with rust_magic:
a) putting dependencies into a separate cell (more)
b) collapsing function bodies with codefolding jupyter extension
c) putting function definitions into separate cells (more)
can be acheived by caching dependencies compile results with sccache.
Rust-magic automatically uses it if it is installed in the system (cargo install sccache
).