Skip to Main Content
Rust Programming Cookbook
book

Rust Programming Cookbook

by Claus Matzinger
October 2019
Intermediate to advanced content levelIntermediate to advanced
444 pages
10h 37m
English
Packt Publishing
Content preview from Rust Programming Cookbook

How to do it...

Here's how to write low-latency web applications in just a few steps:

  1. Let's start by implementing the Rust part. We'll again create a hashing library, so we start by creating the API basics. Open rust-digest/src/lib.rs and insert the following above the tests:
use sha2::{Sha256, Digest};use wasm_bindgen::prelude::*;fn hex_digest(data: &str) -> String {    let mut hasher = Sha256::new();    hasher.input(data.as_bytes());    let signature = hasher.result();    signature        .as_ref()        .iter()        .map(|b| format!("{:X}", b))        .collect::<String>()}
  1. Let's bind the hex_digest() function to a public API that we can call from outside the module. This enables us to invoke the code using WASM types and even autogenerate most of these bindings. Add some ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust Web Programming

Rust Web Programming

Maxwell Flitton
The Complete Rust Programming Reference Guide

The Complete Rust Programming Reference Guide

Rahul Sharma, Vesa Kaihlavirta, Claus Matzinger

Publisher Resources

ISBN: 9781789530667Supplemental Content