• Stars
    star
    1,764
  • Rank 26,386 (Top 0.6 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An introduction to the Rust programming language for Node developers.

Rust for Node developers

An introduction to the Rust programming language for Node developers.

💡 2nd edition. I initially wrote this tutorial in the summer of 2016. Rust 1.0 was roughly a year old back than. This tutorial stayed quite popular over time even though I haven't added new chapters. As years passed by the Rust (and Node) ecosystem evolved further and this tutorial wasn't up-to-date with all changes. With the recent release of "Rust 2018" (which I'll explain later in more depth) I took the opportunity to update this tutorial as well. Enjoy the read! 🎉

Hi there, I'm Donald. I'm a JavaScript developer who wants to learn Rust and as a part of this process I'll write here about my learnings. But what is Rust and why do I want to learn it? Rust is a systems programming language like C or C++, but with influences from functional programming languages and even scripting languages like JavaScript. It feels very modern - which is no surprise, because it is a relatively young language. It went 1.0 in 2015! That doesn't only mean it is fun to write, because it has less clutter to carry around, it is also fun to use, because it has a modern toolchain with a great package manager. Rust's most unique feature is probably the compile-time safety check: it catches errors like segfaults without introducing a garbage collector. Or to phrase it differently: maximum safety with maximum performance.

Probably even more important than its features is the ecosystem and the community behind the language. Rust really shines here - especially for people who love the web. The language was (and still is) heavily influenced by developers from Mozilla. They have written servo, a modern browser engine, in Rust and parts of Firefox are now running Rust code. Rust is also great for authoring WebAssembly code (short: Wasm), a binary format for the web, which is supported in Firefox, Edge, Chrome and Safari.

To summarize: Rust is a young modern language with a great tooling and ecosystem, good safety and performance promises and which can be used for a lot of different projects - from low level tasks to command line tools and even web projects.

Before we dive into our tutorial we want to look at least once into a real Rust file:

fn main() {
    println!("Hello World!");
}

The JavaScript equivalent could roughly look like this:

function main() {
  console.log('Hello World!');
}

Nothing too scary, right? The ! behind println could be a bit confusing, but don't mind it for now. Just think of it as a special function.

How do we move on from here? First I'll guide you how my current setup looks like to use Node and Rust. Many people seemed to like that I introduce some convenient tooling and IDE configurations before actually speaking about Rust itself. But you can skip this chapter, if you want. After the setup step I'll create several kitchen sink like examples - first with Node and then with Rust. I'll try to explain them as best as I can, but don't expect in-depth explanations in every case. Don't forget that I'm trying to learn Rust - just like you. Probably you need to explain me some things, too! And before I forget it: my Node examples will be written in TypeScript! Writing them in TypeScript will make it a little bit easier to compare some examples to Rust.

One word about the structure of this tutorial before we start. Every chapter has its own directory. If a chapter has sub-chapters they also have sub-directories. And if a (subd-)chapter contains code examples, you'll find a node and a rust directory which contain all the code of this (sub-)chapter. (One example: The chapter "Package Manager" can be found inside package-manager/. It has the sub-chapter "Publishing" and the corresponding code examples can be found in package-manager/publishing/node/ and package-manager/publishing/rust/.)

Table of contents

  1. Setup
  2. Hello World
  3. Package Manager
  4. Read files
  5. Write files
  6. HTTP requests
  7. Parse JSON

Thank you for reading this tutorial. ♥

I highly appreciate pull requests for grammar and spelling fixes as I'm not a native speaker. Thank you!

More Repositories

1

component-check

A quick introduction to exploring how components can be created in several frameworks.
465
star
2

dwatch

Manage your docker containers, images and networks in a nice and clean way.
TypeScript
147
star
3

serverless-image-processor

AWS Lambda image processor
TypeScript
105
star
4

react-with-typescript

Small examples which show how React can be used with TypeScript
TypeScript
90
star
5

e2e-check

A simple overview about current E2E testing solutions for web apps.
TypeScript
37
star
6

spring-security-jwt

JWT support for spring-security
Java
30
star
7

rest-schemagen

Jersey add-on for dynamic link and schema building
Java
17
star
8

factcast

This project is archived. A friendly fork can be found at https://github.com/factcast/factcast/
Java
14
star
9

ws

scripts for building web projects
TypeScript
13
star
10

less-plugin-bower-resolve

Import Less files from Bower packages
JavaScript
11
star
11

rest-hateoas-client

Java
8
star
12

test-clock

A windable clock for tests.
Java
8
star
13

frontend-unit-tests-examples

How to write unit tests in our current frontend stack.
TypeScript
5
star
14

default-immutables

Default-Styles and Helper-Classes for common use cases of Immutables.
Java
5
star
15

how-to-debug-javascript

To console.log or to not console.log?
HTML
4
star
16

jsonhoist

Library for chained JSON Transformation (for instance Up-/Down-casting) according to a ruleset stored in a repository.
Java
4
star
17

sqs-utils

Java
3
star
18

reform

3
star
19

reflection

Java
2
star
20

functionaljava-demo

Java
2
star
21

json-schema

Configurable JSON schema generation. Rewrite of JSON schema component of rest-schemagen.
Kotlin
2
star
22

react-remove-props-loader

Webpack loader for removing React props or JSX attributes in TypeScript/JavaScript code.
TypeScript
2
star
23

cycle-live-edit-starter

A starter template which shows how to get live editing features for CSS, HTML and JS in a Cycle.js application.
JavaScript
2
star
24

ddd-applied

eventsourced DDD example implementation
Kotlin
2
star
25

mercateo-spring-boot-starter-hornetq-cluster

mercateo-spring-boot-starter-hornetq-cluster
Java
2
star
26

import-inject-loader

Overwrite your dependencies with mocks and custom implementations.
JavaScript
2
star
27

rest-jersey-utils

Java
2
star
28

counter-component-with-react-mobx-fela

This an example which shows how you can create a component with React, MobX and Fela.
TypeScript
1
star
29

typedocs

Generate documentation for TypeScript projects.
TypeScript
1
star
30

rest-schemagen-spring

Spring configuration for common.rest.schemagen
Java
1
star
31

github-node-client-demo

JavaScript
1
star
32

sb-status

Ops tool to retrieve Health Status of a running Boot Application as well as its maven version
Java
1
star
33

live-edit-starter

A starter template which shows how to get live editing features for CSS, HTML and JS.
JavaScript
1
star
34

rest-demo-feature

Java
1
star