# 고급 lifetime (Rust) > Higher-ranked trait bounds (HRTB), lifetime subtyping, variance (covariant, contravariant, invariant), 'static vs 'a, NLL - 20 면접 질문 - Senior - [면접 질문: Rust](https://sharpskill.dev/ko/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/ko/login ## 기타 Rust 면접 주제 - [Rust 기초](https://sharpskill.dev/ko/technologies/rust/interview-questions/rust-basics.md): 25개 질문, Junior - [Ownership & Borrowing](https://sharpskill.dev/ko/technologies/rust/interview-questions/ownership-borrowing.md): 22개 질문, Junior - [Structs & Enums](https://sharpskill.dev/ko/technologies/rust/interview-questions/structs-enums.md): 20개 질문, Junior - [에러 처리](https://sharpskill.dev/ko/technologies/rust/interview-questions/error-handling.md): 18개 질문, Junior - [컬렉션](https://sharpskill.dev/ko/technologies/rust/interview-questions/collections.md): 20개 질문, Junior - [모듈과 패키지](https://sharpskill.dev/ko/technologies/rust/interview-questions/modules-packages.md): 18개 질문, Junior - [Traits](https://sharpskill.dev/ko/technologies/rust/interview-questions/traits.md): 22개 질문, Mid-Level - [Generics](https://sharpskill.dev/ko/technologies/rust/interview-questions/generics.md): 20개 질문, Mid-Level - [Lifetimes](https://sharpskill.dev/ko/technologies/rust/interview-questions/lifetimes.md): 20개 질문, Mid-Level - [Iterators & Closures](https://sharpskill.dev/ko/technologies/rust/interview-questions/iterators-closures.md): 22개 질문, Mid-Level - [Smart Pointers](https://sharpskill.dev/ko/technologies/rust/interview-questions/smart-pointers.md): 22개 질문, Mid-Level - [Concurrency Basics](https://sharpskill.dev/ko/technologies/rust/interview-questions/concurrency-basics.md): 20개 질문, Mid-Level - [async/await](https://sharpskill.dev/ko/technologies/rust/interview-questions/async-await.md): 22개 질문, Mid-Level - [Testing](https://sharpskill.dev/ko/technologies/rust/interview-questions/testing.md): 18개 질문, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/ko/technologies/rust/interview-questions/cargo-ecosystem.md): 18개 질문, Mid-Level - [Pattern Matching](https://sharpskill.dev/ko/technologies/rust/interview-questions/pattern-matching.md): 18개 질문, Mid-Level - [매크로](https://sharpskill.dev/ko/technologies/rust/interview-questions/macros.md): 20개 질문, Mid-Level - [Serde와 직렬화](https://sharpskill.dev/ko/technologies/rust/interview-questions/serde-serialization.md): 20개 질문, Mid-Level - [Unsafe Rust](https://sharpskill.dev/ko/technologies/rust/interview-questions/unsafe-rust.md): 20개 질문, Senior - [고급 트레잇](https://sharpskill.dev/ko/technologies/rust/interview-questions/advanced-traits.md): 22개 질문, Senior - [Type System](https://sharpskill.dev/ko/technologies/rust/interview-questions/type-system.md): 20개 질문, Senior - [Tokio & Async I/O](https://sharpskill.dev/ko/technologies/rust/interview-questions/tokio-async.md): 22개 질문, Senior - [성능 최적화](https://sharpskill.dev/ko/technologies/rust/interview-questions/performance-optimization.md): 20개 질문, Senior - [Memory Management](https://sharpskill.dev/ko/technologies/rust/interview-questions/memory-management.md): 20개 질문, Senior - [Web Frameworks](https://sharpskill.dev/ko/technologies/rust/interview-questions/web-frameworks.md): 22개 질문, Senior - [Database Integration](https://sharpskill.dev/ko/technologies/rust/interview-questions/database-integration.md): 20개 질문, Senior - [Rust 디자인 패턴](https://sharpskill.dev/ko/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/ko/technologies/rust/interview-questions/advanced-lifetimes