• Stars
    star
    3,348
  • Rank 13,385 (Top 0.3 %)
  • Language
    Rust
  • License
    Other
  • Created over 9 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

Rust for C++ programmers

Rust For Systems Programmers

A Rust tutorial for experienced C and C++ programmers.

Jump to contents. Jump to contributing.

This tutorial is intended for programmers who already know how pointers and references work and are used to systems programming concepts such as integer widths and memory management. We intend to cover, primarily, the differences between Rust and C++ to get you writing Rust programs quickly without lots of fluff you probably already know.

Hopefully, Rust is a pretty intuitive language for C++ programmers. Most of the syntax is pretty similar. The big difference (in my experience) is that the sometimes vague concepts of good systems programming are strictly enforced by the compiler. This can be infuriating at first - there are things you want to do, but the compiler won't let you (at least in safe code), and sometimes these things are safe, but you can't convince the compiler of that. However, you'll quickly develop a good intuition for what is allowed. Communicating your own notions of memory safety to the compiler requires some new and sometimes complicated type annotations. But if you have a strong idea of lifetimes for your objects and experience with generic programming, they shouldn't be too tough to learn.

This tutorial started as a series of blog posts. Partly as an aid for me (@nrc) learning Rust (there is no better way to check that you have learnt something than to try and explain it to somebody else) and partly because I found the existing resources for learning Rust unsatisfactory - they spent too much time on the basics that I already knew and used higher level intuitions to describe concepts that could better be explained to me using lower level intuitions. Since then, the documentation for Rust has got much better, but I still think that existing C++ programmers are an audience who are a natural target for Rust, but are not particularly well catered for.

Contents

  1. Introduction - Hello world!
  2. Control flow
  3. Primitive types and operators
  4. Unique pointers
  5. Borrowed pointers
  6. Rc and raw pointers
  7. Data types
  8. Destructuring pt 1
  9. Destructuring pt 2
  10. Arrays and vecs
  11. Graphs and arena allocation
  12. Closures and first-class functions

Other resources

  • The Rust book/guide - the best place for learning Rust in general and probably the best place to go for a second opinion on stuff here or for stuff not covered.
  • Rust API documentation - detailed documentation for the Rust libraries.
  • The Rust reference manual - a little out of date in places, but thorough; good for looking up details.
  • Discuss forum - general forum for discussion or questions about using and learning Rust.
  • StackOverflow Rust questions - answers to many beginner and advanced questions about Rust, but be careful though - Rust has changed a lot over the years and some of the answers might be very out of date.
  • A Firehose of Rust - a recorded talk introducing C++ programmers to how lifetimes, mutable aliasing, and move semantics work in Rust

Contributing

Yes please!

If you spot a typo or mistake, please submit a PR, don't be shy! Please feel free to file an issue for larger changes or for new chapters you'd like to see. I'd also be happy to see re-organisation of existing work or expanded examples, if you feel the tutorial could be improved in those ways.

If you'd like to contribute a paragraph, section, or chapter please do! If you want ideas for things to cover, see the list of issues, in particular those tagged new material. If you're not sure of something, please get in touch by pinging me here (@nrc) or on irc (nrc, on #rust or #rust-internals).

Style

Obviously, the intended audience is C++ programmers. The tutorial should concentrate on things that will be new to experienced C++ programmers, rather than a general audience (although, I don't assume the audience is familiar with the most recent versions of C++). I'd like to avoid too much basic material and definitely avoid too much overlap with other resources, in particular the Rust guide/book.

Work on edge case use cases (e.g., using a different build system from Cargo, or writing syntax extensions, using unstable APIs) is definitely welcome, as is in-depth work on topics already covered at a high level.

I'd like to avoid recipe-style examples for converting C++ code to Rust code, but small examples of this kind are OK.

Use of different formats (e.g., question and answer/FAQs, or larger worked examples) are welcome.

I don't plan on adding exercises or suggestions for mini-projects, but if you're interested in that, let me know.

I'm aiming for a fairly academic tone, but not too dry. All writing should be in English (British English, not American English; although I would be very happy to have localisations/translations into any language, including American English) and be valid GitHub markdown. For advice on writing style, grammar, punctuation, etc. see the Oxford Style Manual or The Economist Style Guide. Please limit width to 80 columns. I am a fan of the Oxford comma.

Don't feel like work has to be perfect to be submitted, I'm happy to edit and I'm sure other people will be in the future.

More Repositories

1

derive-new

derive simple constructor functions for Rust structs
Rust
525
star
2

libhoare

Design by contract style assertions for Rust
Rust
247
star
3

graphql

A Rust GraphQL server framework
Rust
236
star
4

xmas-elf

elf parser and navigation tool, pure Rust
Rust
157
star
5

rustaceans.org

Backing data for
150
star
6

ezio

Easy IO for Rust
Rust
104
star
7

portable-interoperable

Async fundamentals initiative: portable and interoperable
75
star
8

apr-intro

An alternate introdcution to the APR book
60
star
9

talks

Slides and artifacts for talks
58
star
10

stupid-stats

Tutorial and demo of rust compiler replacement tooling
Rust
54
star
11

proc-macro-rules

Macro-rules-style syntax matching for procedural macros
Rust
51
star
12

error-docs

Documentation of Rust error handling
48
star
13

zero

A Rust library for zero-allocation parsing of binary data.
Rust
47
star
14

darkly

Rust
40
star
15

callgraph.rs

Callgraphs for Rust programs
Rust
32
star
16

rfc-index

A curated index of Rust RFCs
Rust
27
star
17

find-work

find something Rusty to work on
Rust
20
star
18

big-book-ffi

The Big Book of Rust Interop
20
star
19

provide-any

Proposed API for type-driven member access
Rust
12
star
20

leb128

Implementation of LEB128 encoding in Rust
Rust
9
star
21

mentor-rfcs

A place to improve your RFC writing skills and collaborate on writing RFCs
9
star
22

async-io-traits

Async versions of io traits
Rust
8
star
23

tikv-bench

Rust
7
star
24

rust-dxr

Rust indexing in DXR
7
star
25

rustdoc-highlight

A Rust syntax highlighting library
Rust
5
star
26

box-error

A library for error handling using boxed errors
Rust
4
star
27

clyde

wip
Rust
3
star
28

grpc-snoop

A tool to capture TiKV gRPC messages
Go
3
star
29

gh-velocity

measure the velocity of PRs landing in GitHub
Rust
3
star
30

survey-processing

Utility code for processing Rust's annual survey
Rust
3
star
31

N

PL Semantics Tool
Python
3
star
32

parcom

Rust
2
star
33

tmit

This Month in TiKV
2
star
34

owned-buf

An owned buffer type for reading into possibly uninitialized memory
Rust
2
star
35

github-issues-import

Fork of IQAndreas/github-issues-import
Python
2
star
36

triage

Scripts for helping with Rust issue triage
JavaScript
2
star
37

rustc-perf-data

1
star
38

grpc-benchmark

Shell
1
star
39

macro-libs

Design a proc macro library for Rust
1
star
40

collections

having some fun implementing basic data structures in Rust
Rust
1
star
41

fmtfmt

very WIP ideas for a generic formatting tool
Rust
1
star
42

read-buf

Very sketchy experimentation with ReadBuf things
Rust
1
star
43

raft-proto

Rust
1
star
44

ios-apnea

experiments in ios apps (an apnea timer)
Swift
1
star
45

ray

Rust and JS ray tracers
Rust
1
star
46

derive-display-rfc

repo for collaborating on an RFC for derive display
1
star
47

grpc-rs-squashed

grpc-rs without any Git history
Rust
1
star