General Rust IV
1.
What is the role of the `Deref` trait in Rust?
To handle exceptions
To represent a numeric type
To define a generic type
To overload the dereference operator (`*`)
2.
What is the purpose of the `match` keyword in Rust?
To specify a generic type
To define a loop
To declare a constant
To perform exhaustive pattern matching
3.
What is the purpose of the `std::env::args` function in Rust?
To handle exceptions
To define a new module
To perform arithmetic operations
To retrieve command-line arguments as an iterator
4.
How does Rust manage mutable references and immutability in the same scope?
By allowing implicit conversions
By relying on garbage collection
By using automatic reference counting
By using the borrowing rules to ensure safety
5.
What is the purpose of the `PhantomData` type in Rust?
To represent a numeric type
To declare a constant
To create a new module
To act as a marker for lifetimes or data ownership
6.
What does the `#[cfg(test)]` attribute indicate in Rust?
That the code is part of a benchmark
That the following code is specific to test configurations
That the code should be conditionally compiled
That the code should be ignored by the compiler
7.
How does Rust ensure thread safety with the `Send` trait?
By using global locks and mutexes
By enforcing runtime checks
By indicating that a type can be safely transferred between threads
By relying on automatic reference counting
8.
How does Rust handle stack and heap memory allocation?
It relies entirely on garbage collection
Heap for fixed-size data, stack for dynamic or variable-sized data
Both stack and heap for all data types
Stack for fixed-size data, heap for dynamic or variable-sized data
9.
What is the purpose of the `Copy` trait in Rust?
To represent a numeric type
To define a macro
To create deep copies of values
To handle exceptions
10.
How does Rust implement ownership and borrowing for strings?
By relying on global variables
Using the `String` type and references
Through automatic reference counting
By enforcing runtime checks
11.
How does Rust handle lifetimes in function parameters?
By relying on garbage collection
Through explicit lifetime annotations
By automatic lifetime inference
By using the `lifetime` keyword
12.
What is the purpose of the `Mutex` type in Rust?
To represent a tuple
To provide interior mutability with exclusive access
To declare a constant
To define a generic type
13.
How does Rust handle the absence of a value without using `Option` or `Result`?
By using the `unwrap` method
By returning a default value
By panicking
By relying on garbage collection
14.
What does the `async` keyword indicate in Rust?
That the function is unsafe
That the function is a generator
That the function will execute asynchronously
That the function is a closure
15.
How does Rust handle function overloading?
By using traits and generics
By relying on garbage collection
Through runtime checks
By allowing implicit conversions
16.
What is the purpose of the `Cow` type in Rust?
To represent a collection of values
To handle ownership of a value
To manage the lifetime of a variable
To efficiently handle both owned and borrowed data
17.
How does Rust handle the ownership of closures?
By inferring the ownership based on the environment
By automatically promoting closures to global scope
By using the `box` keyword
By relying on garbage collection
18.
What is the purpose of the `std::fs::File` type in Rust?
To represent a numeric type
To create a new module
To handle file I/O operations
To define a structure
19.
How does Rust manage resources when a thread panics?
By invoking the `panic_handler` function
By unwinding the stack
By relying on garbage collection
By terminating the program abruptly
20.
How does Rust support pattern matching in function parameters?
Through automatic reference counting
By relying on garbage collection
By using the `match` keyword
By using wildcard parameters