Rust Environment

Setup

Build the Rust Environment

Dependencies.

apt-get -qq update
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends \
  build-essential gfortran cmake automake libtool libltdl-dev pkg-config \
  libzmq3-dev
apt-get clean
rm -r /var/lib/apt/lists/* # Clear package list so it isn't stale

Install Jupyter.

pip install --upgrade jupyter jupyter_client

Download Rust installer.

FILENAME="rust-${RUST_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
FILEURL="https://static.rust-lang.org/dist/${FILENAME}"

wget -qO - https://keybase.io/rust/key.asc | gpg --import -
wget --progres=dot:giga $FILEURL ${FILEURL}.asc
gpg --verify ${FILENAME}.asc $FILENAME
cp $FILENAME /results/
rust-1.37.0-x86_64-unknown-linux-gnu.tar.gz

Install.

tar -zxf 
rust-1.37.0-x86_64-unknown-linux-gnu.tar.gz
cd rust-${RUST_VERSION}-x86_64-unknown-linux-gnu ./install.sh --prefix=/opt/rust cd .. rm -r rust-${RUST_VERSION}-x86_64-unknown-linux-gnu

Install EvCxR_Jupyter, and a package to allow us to print the version.

cargo install evcxr_jupyter evcxr_runtime
evcxr_jupyter --install

Check.

du -hsx /
rustc --version
jupyter kernelspec list

Test

println!("Hello world");
eprintln!("Hello error");
format!("Hello {}", "world")
"Hello world"
377.4s
Rust
Rust
extern crate image;
extern crate base64;

pub trait EvcxrResult {fn evcxr_display(&self);}

impl EvcxrResult for image::RgbImage {
    fn evcxr_display(&self) {
        let mut buffer = Vec::new();
        image::png::PNGEncoder::new(&mut buffer).encode(&**self, self.width(), self.height(),
            image::ColorType::RGB(8)).unwrap();
        let img = base64::encode(&buffer);
        println!("EVCXR_BEGIN_CONTENT image/png\n{}\nEVCXR_END_CONTENT", img);        
    }
}
impl EvcxrResult for image::GrayImage {
    fn evcxr_display(&self) {
        let mut buffer = Vec::new();
        image::png::PNGEncoder::new(&mut buffer).encode(&**self, self.width(), self.height(),
            image::ColorType::Gray(8)).unwrap();
        let img = base64::encode(&buffer);
        println!("EVCXR_BEGIN_CONTENT image/png\n{}\nEVCXR_END_CONTENT", img);        
    }
}

image::ImageBuffer::from_fn(256, 256, |x, y| {
    if (x as i32 - y as i32).abs() < 3 {
        image::Rgb([0, 0, 255])
    } else {
        image::Rgb([0, 0, 0])
    }
})