# 高度な lifetime (Rust) > Higher-ranked trait bounds (HRTB)、lifetime subtyping、variance (covariant、contravariant、invariant)、'static と 'a、NLL - 20 面接問題 - Senior - [面接問題: Rust](https://sharpskill.dev/ja/technologies/rust/interview-questions.md) ## 1. Rust における Higher-Ranked Trait Bound (HRTB) とは何ですか? **回答** Higher-Ranked Trait Bound (HRTB) を使うと、関数や trait が特定の lifetime だけでなく、考えられるすべての lifetime に対して機能する必要があることを指定できます。for<'a> という構文は、呼び出し側が選ぶ任意の lifetime 'a に対して trait bound が満たされなければならないことを示します。この機能は、さまざまな lifetime を持つ参照を受け取る必要がある closure や callback にとって不可欠です。 ## 2. fn foo<'a>(f: impl Fn(&'a str)) と fn foo(f: impl for<'a> Fn(&'a str)) の違いは何ですか? **回答** fn foo<'a> の場合、lifetime 'a は呼び出し時に呼び出し側によって固定され、実行全体を通じて同じままです。for<'a> の場合、closure は任意の lifetime に対して機能しなければならず、異なる lifetime の参照で複数回呼び出すことができます。この違いは、異なる一時参照で closure を複数回呼び出す API にとって極めて重要です。 ## 3. Rust における lifetime subtyping とは何ですか、また 'a: 'b は何を意味しますか? **回答** lifetime subtyping は、lifetime 間の subtyping 関係を確立します。'a: 'b という表記は、'a が少なくとも 'b と同じだけ生存することを意味し、したがって 'a は 'b の subtype です。より長い lifetime を持つ参照は、より短い lifetime が期待される場所で使用できます。この関係はイミュータブルな参照に対して covariant であり、より短い lifetime で十分な場所により長い lifetime を持つ参照を渡すことができます。 ## さらに17問利用可能 - Rust における variance とは何ですか、また generic 型にどのような影響を与えますか? - なぜ &mut T は T に対して invariant であるのに対し、&T は covariant なのですか? 無料で登録: 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 - [Lifetimes](https://sharpskill.dev/ja/technologies/rust/interview-questions/lifetimes.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 - [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/advanced-lifetimes