Test Your Knowledge of Advanced Rust Programming Features


Gensen Huang
Idyllic Icon

Gensen Huang

Created 6/20/2024

74

77.91%

Q & A


Share This Quiz

Sources

https://ecstatic-morse.github.io/rust/book/2018-edition/ch19-01-unsafe-rust.html
https://ecstatic-morse.github.io/rust/book/2018-edition/ch19-02-advanced-lifetimes.html
https://ecstatic-morse.github.io/rust/book/2018-edition/ch19-03-advanced-traits.html
https://ecstatic-morse.github.io/rust/book/2018-edition/ch19-04-advanced-types.html

How well do you really know Rust? Put your skills to the test with this quiz on advanced Rust programming features. Can you score a perfect 20/20?

How well do you really know Rust? Put your skills to the test with this quiz on advanced Rust programming features. Can you score a perfect 20/20?

1. What keyword is used in Rust to create an interface that permits other languages to call Rust functions?

extern
unsafe
goto
no_mangle

2. In Rust, what annotation is used to prevent name mangling when making Rust functions accessible from other languages?

#static
#no_mangle
#extern
#unsafe

3. What type of Rust variable can be problematic due to ownership rules, especially when accessed by multiple threads?

struct
enum
static
const

4. Which keyword is used to switch to unsafe Rust?

unsafe
static
pub
extern

5. What is the output of using fully qualified syntax to call the baby_name function as implemented on Dog from the Animal trait?

Error
A baby dog is called a puppy
dog
None

6. What concept in Rust can be used to handle tasks like statically enforcing that values are never confused and indicating units of a value?

Unsafe traits
Static variables
Newtype pattern
Type alias

7. What are the four unsafe superpowers in Rust?

JIT compilation, raw pointers, calling unsafe functions, manual memory management
Raw pointers, calling unsafe functions, mutable static variable access, implementing unsafe traits
Static variables, borrow checker, dereferencing, memory swapping
Reference counting, lifetimes, static mutability, async/await

8. What is the core purpose of lifetime bounds on generic types in Rust?

Verifying that references in generic types won't outlive the data they're referencing
Allowing mutable access to static variables
Guaranteeing C ABI compatibility
Managing thread safety

9. What feature in Rust allows ensuring that one lifetime outlives another?

Lifetime subtyping
Lifetime bounds
Lifetime inference
Static typing

10. Which keyword in Rust is used to declare a block of code that integrates functions from another language?

extern
pub
mod
unsafe

11. How does Rust handle calling methods of the same name from different traits implemented on one type?

It allows calling without disambiguation
It throws a compile-time error
It uses fully qualified syntax to specify the trait
It silently selects one trait based on priority

12. What mechanism does Rust provide to call methods with the same name but different traits on an instance?

Dynamic dispatch
Fully qualified syntax
Trait overloading
Macro expansion

13. In the context of advanced traits in Rust, what is a supertrait?

A trait that depends on another trait's functionality
A trait that implements another trait's methods
A globally available trait
A trait exclusively for unsafe code

14. What feature allows specifying a placeholder for types in trait definitions in Rust?

Associated types
Type aliases
Lifetime bounds
Constraints

15. What term defines how to call a function at the assembly level and is used with the extern keyword?

ABI (Application Binary Interface)
FFI (Foreign Function Interface)
MQ (Memory Queue)
RSI (Rust Standard Interface)

16. Which Rust feature helps when two types in the same scope implement a trait with an associated function of the same name?

Unsafe code
Type aliases
Fully qualified syntax
Macros

17. What is a 'raw pointer' in Rust?

A pointer that guarantees safety of referenced data
A pointer type that is similar to references but can be used in unsafe code
A default pointer type in safe Rust
A type of iterator in collections

18. Which of the following is NOT one of the four unsafe superpowers in Rust?

Calling an unsafe function or method
Dereferencing a raw pointer
Implementing an unsafe trait
Dynamic dispatch

19. When using trait objects in Rust, what syntax ensures proper handling of dynamically sized types?

Placing the trait object behind a pointer such as &Trait or Box<Trait>
Using static variables
Leveraging associated types
Employing unsafe blocks

20. What is the purpose of adding the #[no_mangle] attribute to Rust functions?

To prevent lifetime issues
To avoid memory leaks
To prevent the compiler from changing the function name
To enable dynamic dispatch