Penflip

Penflip - Write better with others

  • Loading...
  • Discover Projects
  • Help
  • Signup
  • Login
  • Welcome back!
    No account? Signup Close
    Ready to write better?
    Have an account? Login Close

sarojaba · Rust Doc Korean

Make Changes
46

5.16. 벡터 (Vectors) - 100%

'vector'는 동적이고 크기가 커질 수 있는(growable) 배열이며, 표준 라이브러리 타입 <code>Vec<T></code>으로서 구현되었습니다. T가 의미하는 바는, 어떤 타입에 대한 벡터도 만들 수 있다는 뜻입니다(더 자세한 것은 generics 챕터를 보세요). 벡터는 항상 그 데이터를 힙에 할당합니다. 벡터는 vec! 매크로를 이용해서 만들 수 있습니다:

let v = vec![1, 2, 3, 4, 5]; // v: Vec<i32>

(예전에 썼던 println!매크로와 달리, vec!매크로를 대괄호 []와 함께 쓴 것에 유의합시다. Rust는 양쪽을 양쪽의 상황에 다 쓸 수 있지만, 이것은 일단 관습입니다.)

반복되는 초기화 값을 위해 vec!에는 또다른 형태가 있습니다:

let v = vec![0; 10]; // ten zeroes

원소에 접근하기

벡터에서 특별한 인덱스 값의 위치에 있는 값을 구하기 위해서는 []을 사용합니다:

let v = vec![1, 2, 3, 4, 5];

println!("The third element of v is {}", v[2]);

인덱스들의 카운트는 0부터 시작하며, 따라서 세번째 원소는 v[2]가 됩니다.

반복탐색(Iterating)

일단 벡터를 만들고 나면, for와 그 원소들을 사용하여 반복탐색(역자 주: 원문은 iterate이나, 반복자를 이용한 탐색 및 접근을 의미하기에 반복탐색으로 번역함)을 할 수 있습니다. 여기에는 세가지 버젼이 있습니다:

let mut v = vec![1, 2, 3, 4, 5];

for i in &v {
    println!("A reference to {}", i);
}

for i in &mut v {
    println!("A mutable reference to {}", i);
}

for i in v {
    println!("Take ownership of the vector and its element {}", i);
}

벡터는 많은 유용한 메쏘드들을 가지고 있으며, 이에 대해서는 벡터 API 문서에서 읽을 수 있습니다.

Updated by sarojaba almost 4 years (view history)
5.15. 메소드 문법 (Method Syntax) - 100% 5.17. 문자열(Strings) - 100%

Contents

    Rust 문서 한글화 프로젝트 1. 소개(Introduction) 2. 시작하기(Getting Started) - 20% 3. Rust 배우기 (Learn Rust) - 100% 3.1. 추리 게임 (Guessing Game) - 100% 3.2. 식사하는 철학자들 (Dining Philosophers) - 100% 3.3. 다른 언어에 Rust 포함하기 (Rust Inside Other Languages) - 100% 4. 효과적인 Rust (Effective Rust) - 100% 4.1. 스택과 힙 (The Stack and the Heap) - 100% 4.2. 테스팅 (Testing) - 100% 4.3. 조건부 컴파일 (Conditional Compilation) - 70% 4.4. 문서화 (Documentation) - 20% 4.5. 반복자 (Iterators) - 100% 4.6. 동시성 (Concurrency) - 90% 4.7. 오류 처리 (Error Handling) - 0% 4.8. Choosing your Guarantees - 0% 4.9. 외부 함수 인터페이스 (Foreign Function Interface) - 50% 4.9. Borrow 와 AsRef 4.11. 배포 채널 (Release Channels) - 80% 5. 문법과 의미 (Syntax and Semantics) - 100% 5.1. 변수 바인딩 (Variable Bindings) - 100% 5.2. 함수 (Functions) - 100% 5.3. 기본형 (Primitive Types) - 100% 5.4. 주석 (Comments) - 100% 5.5. 조건식 (if) - 100% 5.6. 반복 (Loops) - 100% 5.7. 소유권 (Ownership) - 100% 5.8. 참조와 빌림 (References and Borrowing) - 100% 5.9. 수명 (Lifetimes) - 100% 5.10. 가변성 (Mutability) - 99% 5.11. 구조체 (Structs) - 100% 5.12. 열거형 (Enums) - 100% 5.13. 정합 (Match) - 100% 5.14. 패턴 (Patterns) - 80% 5.15. 메소드 문법 (Method Syntax) - 100% 5.16. 벡터 (Vectors) - 100% 5.17. 문자열(Strings) - 100% 5.18. 제너릭 (Generics) - 100% 5.19. 트레잇 (Traits) - 100% 5.20. 드랍 (Drop) - 100% 5.21. if let - 100% 5.22. 트레잇 객체 (Trait Objects) - 75% 5.23. 클로저 (Closures) - 10% 5.24. Universal Function Call Syntax 5.25. Crates and Modules 9. 용어 색인 (Concordance) Show all
    Discussions 5 Pending changes 5 Contributors
    Download Share

    Download

    Working...

    Downloading...

    Downloaded!

    Download more

    Error!

    Your download couldn't be processed. Check for abnormalities and incorrect syntax. We've been notified of the issue.

    Back

    Download PDF Download ePub Download HTML Download Word doc Download text Download source (archive)

    Close
215 Words
1,168 Characters

Share

Collaborators make changes on their own versions, and all changes will be approved before merged into the main version.

Close

Penflip is made by Loren Burton
in Los Angeles, California

Tweet

    About

  • Team
  • Pricing
  • Our Story

    Quick Start

  • Markdown
  • Penflip Basics
  • Working Offline

    Support

  • Help
  • Feedback
  • Terms & Privacy

    Connect

  • Email
  • Twitter