Rust Flashcards
Does rust build debug or release builds by default?
Debug
How do you make rustc or cargo do a release build?
Use the –release with cargo or -O with rustc.
How do you enable Link-Time Optimization (LTO) in rust?
Under a profile in your Cargo.toml…
[profile.release]
lto=true
What is the purpose of Codegen Units?
To parallelize compilation.
What is a potential drawback of using Codegen Units?
Some compiler optimizations may be missed.
How do you compile for a specific architecture in Rust?
Use the -target-cpu flag.
How do you compile for your CPU’s current architecture?
-target-cpu=native
What is a build optimization you can use related to panics?
You can configure your Cargo.toml to abort on panics if you don’t need to catch or unwind them…
[profile.release]
panic=”abort”
How do you suggest to the compiler to inline a function?
Use the #[inline] attribute.
What are the 3 different inline attributes and what do they do?
#[inline] = suggests to the compiler to inline the function #[inline(always)] = strongly suggests to the compiler to inline the function, works across crate bounds #[inline(never)] = strongly suggests to the compiler to not inline the function
Do inline attributes guarantee that the compiler will inline the function?
No.
What are const generics?
Generic parameters that range over constant values.
example: struct ArrayPair { left: [T; N], right: [T; N], }
What are generic type parameters
Generic parameters that range over types.
```
example:
fn two_copies(item: &T) -> (T, T
where
T: Clone,
{
item.clone(), item.clone())
}
~~~
What kind of items can have generic parameters?
Functions, type aliases, structs, enumerations, unions, traits, and implementations
What are the three kinds of generic parameters?
Types, constants, and lifetimes