Functional Data Structures
- What is a good library to serialize and deserialize data?
We recommend serde
.
- What do the hashtag derive lines in front of the struct declarations in
physics.rs
do?
These are macros that will automatically derive trait implementations for these data structures.
- Which comes first in parameterized declarations—lifetimes or traits?
Lifetime parameters must come before trait parameters in parameter declarations.
- In a trait implementation, what is the difference between parameters on the impl, trait, or type?
The impl<A,...>
syntax defines what symbols will be parameterized. The Trait<A,...>
syntax defines what trait is being implemented. The Type<A,...>
syntax defines what type the trait is being implemented for.
- What is the difference between a trait and a data class?
The term data class is not a Rust term. Think of a data class as if it were a trait but without fewer limitations than what Rust might impose.
- How should you declare that a package has multiple binaries?
In Cargo.toml
, list all of the binaries and their entry points:
[[bin]] name = "binary1" path = "binary1.rs" [[bin]] name = "binary2" path = "binary2.rs"
- How do you declare a structure field as private?
Do not declare it as public
. Fields are private
by default.