General Rust VI
1.
What is the purpose of the `std::slice::from_raw_parts` function in Rust?
Reverses the elements of a slice
Converts a slice to a raw pointer
Creates a slice from a raw pointer and length
Returns the size of a slice
2.
How does Rust handle panics in a `const fn`?
By converting panics to compile-time errors
By invoking the `panic_handler` function
By unwinding the stack
By not allowing panics in `const fn`
3.
What is the role of the `Drop` trait in Rust?
To represent a numeric type
To handle exceptions in Rust
To define custom cleanup code when a value goes out of scope
To specify a lifetime
4.
What is the purpose of the `panic!` macro in Rust?
To create a constant
To define a new module
To indicate a runtime panic and unwind the stack
To handle exceptions
5.
How does Rust ensure thread safety with the `Send` trait?
By enforcing runtime checks
By using global locks and mutexes
By relying on garbage collection
By indicating that a type can be safely transferred between threads
6.
What is the purpose of the `#[derive(PartialEq)]` attribute in Rust?
Indicates a macro
Declares a constant
Automatically implements the `PartialEq` trait for a type
Specifies the visibility of a variable
7.
What is the purpose of the `std::time::Duration` type in Rust?
To represent a date and time
To define a macro
To handle exceptions
To represent a duration of time
8.
What is the purpose of the `derive` attribute for enums in Rust?
To automatically implement common traits
To declare a constant
To create a new module
To handle exceptions
9.
What is the purpose of the `std::mem::transmute` function in Rust?
To represent a numeric type
Unsafe transmutation of types
To create a new module
To handle exceptions
10.
What is the purpose of the `std::fmt::Debug` trait in Rust?
To format a value for debugging output
To define a macro
To represent a numeric type
To handle exceptions
11.
What does the `std::collections::HashMap::insert` method do in Rust?
Inserts a key-value pair into the HashMap
Removes a key-value pair from the HashMap
Retrieves a value associated with a key
Sorts the HashMap keys
12.
How does Rust enforce ownership rules for function parameters?
By using automatic reference counting
By transferring ownership
Through explicit ownership annotations
By relying on garbage collection
13.
What is the purpose of the `std::io::Read` trait in Rust?
To represent a numeric type
To handle file I/O operations
To define a generic type
To implement the comparison operators for a type
14.
How does Rust handle concurrency with the `Arc` type?
By using automatic reference counting
By providing atomic reference counting for shared ownership
By enforcing strict ownership rules
By relying on garbage collection
15.
What does the `as_mut` method do on a mutable reference in Rust?
Converts the mutable reference to a raw pointer
Returns a mutable reference to the same data
Applies a function to the mutable reference
Creates a new mutable reference
16.
How does Rust represent a potentially failed computation?
Using the `Option` type
Using the `Result` type
Using the `Error` type
By relying on garbage collection
17.
How does Rust enforce lifetimes in struct definitions?
By using automatic lifetime inference
Through explicit lifetime annotations
By relying on garbage collection
By specifying the lifetime of a variable
18.
How does Rust handle ownership and borrowing in closures?
By using the `box` keyword
By automatically promoting closures to global scope
Through the use of the `move` keyword
By relying on garbage collection
19.
How does Rust enforce memory safety in unsafe code?
By requiring manual checks and adhering to ownership rules
By using garbage collection
By enforcing strict typing
By relying on runtime checks
20.
How does Rust handle generic programming with lifetimes?
Through lifetime parameters in function and struct definitions
By relying on garbage collection
Through automatic lifetime inference
By using the `lifetime` keyword