General Rust V
1.
What does the `iter` method do on a Rust slice?
Returns an iterator over the elements of the slice
Generates a random permutation of the elements
Sorts the elements in ascending order
Reverses the order of the elements
2.
How does Rust manage dynamic dispatch for trait objects?
By declaring functions as `dynamic`
Automatically without any keyword
By using the `dyn` keyword
By relying on garbage collection
3.
What is the purpose of the `std::mem::swap` function in Rust?
Swaps the values of two variables
Clones a value
Compares two values for equality
Deletes a variable
4.
How does Rust manage lifetime elision for function parameters?
By relying on garbage collection
By inferring lifetimes based on certain rules
Through automatic lifetime inference
By using the `lifetime` keyword
5.
What is the role of the `Rc::clone` method in Rust?
Increments the reference count of an `Rc` smart pointer
Creates a deep copy of the value
Decrements the reference count of an `Rc` smart pointer
Clones a value
6.
How does Rust handle panics in a `Drop` implementation?
By relying on garbage collection
By ignoring the panic
By unwinding the stack
By invoking the `panic_handler` function
7.
What does the `std::sync::Mutex` type provide in Rust?
A non-blocking concurrency mechanism
Thread-safe atomic operations
Exclusive access to shared data
Garbage collection for shared resources
8.
What is the purpose of the `Option::map` method in Rust?
Folds the `Option` into a single value
Concatenates two `Option` values
Applies a function to the inner value if it exists
Filters the `Option` based on a predicate
9.
How does Rust handle concurrency in a single-threaded context?
Using asynchronous programming with the `async/await` syntax
By ignoring concurrency
By enforcing strict ownership rules
By relying on garbage collection
10.
What is the purpose of the `slice::len` method in Rust?
Returns the length of a slice
Returns the capacity of a slice
Reverses the elements of a slice
Filters the elements of a slice based on a predicate
11.
How does Rust handle integer overflow when using the `wrapping_add` method?
By wrapping around to the minimum value
By panicking
By ignoring the overflow
By returning a default value
12.
What is the purpose of the `std::cmp::PartialOrd` trait in Rust?
To implement the comparison operators for a type
To define ordering relationships for partial comparisons
To represent a numeric type
To handle exceptions
13.
How does Rust enforce lifetimes in function signatures?
By using the `lifetime` keyword
By relying on garbage collection
Through automatic lifetime inference
Through explicit lifetime annotations
14.
How does Rust handle ownership when returning a value from a function?
By relying on garbage collection
By creating a deep copy
By creating a reference
By transferring ownership
15.
What is the purpose of the `Cow::Borrowed` variant in Rust?
Signifies a mutable reference
Represents an owned value
Indicates a cloned value
Represents a borrowed reference
16.
What does the `std::cell::RefCell` type provide in Rust?
Exclusive access to shared data
Atomic reference counting
Interior mutability with runtime borrow checking
Non-blocking concurrency
17.
What is the purpose of the `std::env::var` function in Rust?
Retrieves the value of an environment variable
Performs arithmetic operations
Creates a new environment variable
Declares a constant
18.
How does Rust support pattern matching for enums?
Using the `match` keyword
By relying on garbage collection
Through automatic reference counting
By using wildcard patterns
19.
What is the purpose of the `#![allow(dead_code)]` attribute in Rust?
Declares a constant
Suppresses warnings about unused code
Specifies the visibility of a variable
Indicates a macro
20.
How does Rust represent a type that can be either a value or an error?
By relying on garbage collection
Using the `Option` type
Using the `Either` type
Using the `Result` type