Rust Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Does rust build debug or release builds by default?

A

Debug

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you make rustc or cargo do a release build?

A

Use the –release with cargo or -O with rustc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you enable Link-Time Optimization (LTO) in rust?

A

Under a profile in your Cargo.toml…

[profile.release]
lto=true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of Codegen Units?

A

To parallelize compilation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a potential drawback of using Codegen Units?

A

Some compiler optimizations may be missed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you compile for a specific architecture in Rust?

A

Use the -target-cpu flag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you compile for your CPU’s current architecture?

A

-target-cpu=native

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a build optimization you can use related to panics?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you suggest to the compiler to inline a function?

A

Use the #[inline] attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 3 different inline attributes and what do they do?

A
#[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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Do inline attributes guarantee that the compiler will inline the function?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are const generics?

A

Generic parameters that range over constant values.

example:
struct ArrayPair {
    left: [T; N],
    right: [T; N],
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are generic type parameters

A

Generic parameters that range over types.

```
example:
fn two_copies(item: &T) -> (T, T
where
T: Clone,
{
item.clone(), item.clone())
}
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What kind of items can have generic parameters?

A

Functions, type aliases, structs, enumerations, unions, traits, and implementations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the three kinds of generic parameters?

A

Types, constants, and lifetimes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly