
async/await
async functions, Future trait, tokio runtime, async blocks, .await syntax, Streams, Pin<T>, cancellation, executor patterns
1What does a function declared with the async keyword return in Rust?
What does a function declared with the async keyword return in Rust?
Risposta
An async function automatically returns a type that implements the Future trait. The compiler transforms the function body into a state machine that implements Future. The return value is not computed immediately: it will only be calculated when the Future is awaited with .await or executed by a runtime.
2What is the main role of the Future trait in Rust?
What is the main role of the Future trait in Rust?
Risposta
The Future trait represents an asynchronous computation that may not be finished yet. Its poll method allows the executor to check if the Future is ready (Poll::Ready) or needs to wait (Poll::Pending). This is the fundamental mechanism of asynchrony in Rust, enabling non-blocking and efficient execution.
3Why is a runtime like tokio necessary to execute async code in Rust?
Why is a runtime like tokio necessary to execute async code in Rust?
Risposta
Rust does not include an async runtime in its standard library to keep the language minimal and allow choosing the runtime based on needs. A runtime like tokio provides the executor that polls Futures, the scheduler to manage tasks, and async I/O. Without a runtime, Futures would never be executed.
What is the difference between an async block and an async function in Rust?
What happens when using .await on a Future in Rust?
+19 domande da colloquio
Altri argomenti di colloquio Rust
Rust Basics
Ownership & Borrowing
Structs & Enums
Error Handling
Collections
Modules & Packages
Traits
Generics
Lifetimes
Iterators & Closures
Smart Pointers
Concurrency Basics
Testing
Cargo & Ecosystem
Pattern Matching
Macros
Serde & Serialization
Unsafe Rust
Advanced Traits
Advanced Lifetimes
Type System
Tokio & Async I/O
Performance Optimization
Memory Management
Web Frameworks
Database Integration
Rust Design Patterns
Padroneggia Rust per il tuo prossimo colloquio
Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.
Inizia gratis