A collection of various Rust cargo projects, probably from various books and courses, in particular, The Rust Programming Language, Programming Rust, Rust in Action and Programming with Rust.
Each sub-directory is a cargo project. See README.md
there for any project
specific details.
Rust is an expression-based language; almost everything returns something. There are a few exceptions:
- Expressions delimited by
;
- Binding a name to a value with
=
- Type declarations, which include
fn
,struct
andenum
str
is usually seen in this form:&str
(pronounced string slice). It is a small type that contains a reference to str data and a length- Creating
&str
values avoids a memory allocation &str
is a borrowed type. In practical terms, this means that&str
can be thought of as read-only data, whereasString
is read-write[u8]
is slice of raw bytesString
is toVec<u8>
asstr
is to[u8]
- Array notation:
[f32; 12]
is an array of 12 32-bit floating point values [u8; 3]
is a different type than[u8; 4]
- the size of an array mattersVec<Vec<(usize, String)>>
is a vector of vectors (e.g.,Vec<Vec<T>>
), whereT
is a pair of values of type(usize, String)
.(usize, String)
is a tupleVec<T>
performs best when you can provide it with a size hint viaVec::with_ capacity()
In Rust, "no value" is represented as ()
, called "unit".