# Serde와 직렬화 (Rust) > serde 트레이트, derive 매크로, JSON/YAML/TOML, 커스텀 (역)직렬화, Cow를 활용한 라이프타임, 성능 - 20 면접 질문 - Mid-Level - [면접 질문: Rust](https://sharpskill.dev/ko/technologies/rust/interview-questions.md) ## 1. Rust에서 serde 크레이트의 주요 역할은 무엇입니까? **답변** Serde는 Rust를 위한 범용 직렬화 및 역직렬화 프레임워크입니다. 이름은 "SERialize DEserialize"에서 유래했습니다. Rust 데이터 구조를 다양한 데이터 형식(JSON, YAML, TOML 등)으로, 그리고 그로부터 효율적이고 타입 안전하게 변환할 수 있게 해줍니다. Serde는 Rust의 트레이트 시스템을 활용하여 런타임 비용이 없는 추상화를 제공합니다. ## 2. serde로 struct에 자동 직렬화를 활성화하는 올바른 구문은 무엇입니까? **답변** #[derive(Serialize, Deserialize)] 속성은 struct에 대해 Serialize 및 Deserialize 트레이트의 구현을 자동으로 생성합니다. 이 절차적 매크로는 필드 구조를 분석하고 컴파일 타임에 필요한 코드를 생성합니다. use serde::{Serialize, Deserialize}로 serde에서 트레이트를 임포트해야 합니다. ## 3. serde_json으로 Rust struct를 JSON 문자열로 변환하려면 어떤 함수를 사용해야 합니까? **답변** serde_json::to_string() 함수는 Serialize를 구현하는 값을 JSON 문자열로 변환합니다. 직렬화는 특정 경우에 실패할 수 있으므로 Result를 반환합니다. 들여쓰기가 적용된 형식화된 출력에는 serde_json::to_string_pretty()를 사용합니다. Writer에 직접 쓰려면 serde_json::to_writer()를 사용합니다. ## 17개 추가 질문 이용 가능 - serde_json으로 JSON 문자열을 Rust struct로 역직렬화하려면 어떻게 합니까? - 직렬화 중에 필드 이름을 변경하려면 어떤 serde 속성을 사용해야 합니까? 무료로 가입하기: 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 - [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 - [고급 lifetime](https://sharpskill.dev/ko/technologies/rust/interview-questions/advanced-lifetimes.md): 20개 질문, 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/serde-serialization