# Lifetimes (Rust) > Lifetime アノテーション、省略規則、'static lifetime、struct の lifetime、lifetime bounds - 20 面接問題 - Mid-Level - [面接問題: Rust](https://sharpskill.dev/ja/technologies/rust/interview-questions.md) ## 1. Rust における lifetime の主な目的は何ですか? **回答** Lifetime により、compiler はすべての reference が使用中ずっと有効であることを検証できます。reference が参照するデータより長く生存しないことを保証し、dangling reference を防ぎます。borrow checker は lifetime を使用してコンパイル時にメモリ安全性を検証し、実行時のオーバーヘッドはありません。 ## 2. reference に lifetime を注釈するにはどの構文を使いますか? **回答** Lifetime はアポストロフィに続けて名前を付けて注釈します。通常は 'a のような小文字を使います。&'a T という構文は lifetime 'a を持つ T への reference を意味します。慣例として generic な lifetime には 'a, 'b, 'c を使いますが、アポストロフィの後には任意の有効な識別子を使用できます。 ## 3. Rust において 'static lifetime は何を意味しますか? **回答** 'static lifetime は、reference がプログラムの実行期間全体にわたって生存できることを示します。"hello" のような string literal は binary に埋め込まれているため、自動的に 'static lifetime を持ちます。グローバル定数や Box::leak で作成された値もこの lifetime を持ちます。注意:'static は値がプログラム開始時から存在していたという意味ではなく、終了まで生存できるという意味です。 ## さらに17問利用可能 - Rust の compiler は lifetime の省略規則をいくつ自動的に適用しますか? - なぜ関数 fn longest(x: &str, y: &str) -> &str はコンパイルできないのですか? 無料で登録: https://sharpskill.dev/ja/login ## その他のRust面接トピック - [Rustの基礎](https://sharpskill.dev/ja/technologies/rust/interview-questions/rust-basics.md): 25問, Junior - [Ownership & Borrowing](https://sharpskill.dev/ja/technologies/rust/interview-questions/ownership-borrowing.md): 22問, Junior - [Structs & Enums](https://sharpskill.dev/ja/technologies/rust/interview-questions/structs-enums.md): 20問, Junior - [エラー処理](https://sharpskill.dev/ja/technologies/rust/interview-questions/error-handling.md): 18問, Junior - [コレクション](https://sharpskill.dev/ja/technologies/rust/interview-questions/collections.md): 20問, Junior - [モジュールとパッケージ](https://sharpskill.dev/ja/technologies/rust/interview-questions/modules-packages.md): 18問, Junior - [Traits](https://sharpskill.dev/ja/technologies/rust/interview-questions/traits.md): 22問, Mid-Level - [Generics](https://sharpskill.dev/ja/technologies/rust/interview-questions/generics.md): 20問, Mid-Level - [Iterators & Closures](https://sharpskill.dev/ja/technologies/rust/interview-questions/iterators-closures.md): 22問, Mid-Level - [Smart Pointers](https://sharpskill.dev/ja/technologies/rust/interview-questions/smart-pointers.md): 22問, Mid-Level - [Concurrency Basics](https://sharpskill.dev/ja/technologies/rust/interview-questions/concurrency-basics.md): 20問, Mid-Level - [async/await](https://sharpskill.dev/ja/technologies/rust/interview-questions/async-await.md): 22問, Mid-Level - [Testing](https://sharpskill.dev/ja/technologies/rust/interview-questions/testing.md): 18問, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/ja/technologies/rust/interview-questions/cargo-ecosystem.md): 18問, Mid-Level - [Pattern Matching](https://sharpskill.dev/ja/technologies/rust/interview-questions/pattern-matching.md): 18問, Mid-Level - [マクロ](https://sharpskill.dev/ja/technologies/rust/interview-questions/macros.md): 20問, Mid-Level - [Serde とシリアライゼーション](https://sharpskill.dev/ja/technologies/rust/interview-questions/serde-serialization.md): 20問, Mid-Level - [Unsafe Rust](https://sharpskill.dev/ja/technologies/rust/interview-questions/unsafe-rust.md): 20問, Senior - [高度なトレイト](https://sharpskill.dev/ja/technologies/rust/interview-questions/advanced-traits.md): 22問, Senior - [高度な lifetime](https://sharpskill.dev/ja/technologies/rust/interview-questions/advanced-lifetimes.md): 20問, Senior - [Type System](https://sharpskill.dev/ja/technologies/rust/interview-questions/type-system.md): 20問, Senior - [Tokio & Async I/O](https://sharpskill.dev/ja/technologies/rust/interview-questions/tokio-async.md): 22問, Senior - [パフォーマンス最適化](https://sharpskill.dev/ja/technologies/rust/interview-questions/performance-optimization.md): 20問, Senior - [Memory Management](https://sharpskill.dev/ja/technologies/rust/interview-questions/memory-management.md): 20問, Senior - [Web Frameworks](https://sharpskill.dev/ja/technologies/rust/interview-questions/web-frameworks.md): 22問, Senior - [Database Integration](https://sharpskill.dev/ja/technologies/rust/interview-questions/database-integration.md): 20問, Senior - [Rust デザインパターン](https://sharpskill.dev/ja/technologies/rust/interview-questions/design-patterns.md): 20問, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ja/technologies/rust/interview-questions/lifetimes