
Unsafe Rust
Unsafe blocks, raw pointers (*const T, *mut T), FFI, unsafe traits, Undefined Behavior (UB), safety invariants
1Which keyword enables the superpowers of unsafe mode in Rust?
Which keyword enables the superpowers of unsafe mode in Rust?
Câu trả lời
The unsafe keyword unlocks five capabilities forbidden in safe Rust: dereferencing raw pointers, calling unsafe functions, accessing mutable static variables, implementing unsafe traits, and accessing union fields. This block signals to the compiler that the developer takes responsibility for guaranteeing memory safety.
2How many additional capabilities does unsafe code unlock compared to safe Rust?
How many additional capabilities does unsafe code unlock compared to safe Rust?
Câu trả lời
Unsafe mode unlocks exactly five capabilities: dereferencing raw pointers, calling unsafe functions or methods, accessing or modifying mutable static variables, implementing unsafe traits, and accessing union fields. These five operations are the only differences between safe and unsafe Rust.
3What is the correct syntax to create an immutable raw pointer to a variable in Rust?
What is the correct syntax to create an immutable raw pointer to a variable in Rust?
Câu trả lời
The syntax to create an immutable raw pointer is let ptr = &x as *const T. The type *const T represents an immutable raw pointer. Creating raw pointers is safe, only dereferencing requires an unsafe block. Implicit coercion can also be used with let ptr: *const T = &x.
What is the difference between *const T and *mut T in Rust?
Why is creating raw pointers allowed in safe Rust while dereferencing them is not?
+17 câu hỏi phỏng vấn
Các chủ đề phỏng vấn Rust khác
Rust Basics
Ownership & Borrowing
Structs & Enums
Error Handling
Collections
Modules & Packages
Traits
Generics
Lifetimes
Iterators & Closures
Smart Pointers
Concurrency Basics
async/await
Testing
Cargo & Ecosystem
Pattern Matching
Macros
Serde & Serialization
Advanced Traits
Advanced Lifetimes
Type System
Tokio & Async I/O
Performance Optimization
Memory Management
Web Frameworks
Database Integration
Rust Design Patterns
Nắm vững Rust cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí