Updated readme.md

sarojaba authored
revision acde29e48e9859f9eb214ae310c5a464ac8dad8e
readme
# 1. 소개(Introduction)

환영합니다! 이 책은 당신에게 [Rust 프로그래밍 언어](http://www.rust-lang.org/)에 대해 알려줄 것입니다. Rust는 안전성과 속도에 초점을 맞춘 현대의 시스템 프로그래밍 언어입니다. 가비지 컬렉션을 사용하지 않는 메모리 안전성을 목표로 하고 있습니다.

"Rust 프로그래밍 언어"는 세가지 단원으로 구분됩니다. 왼쪽의 메뉴를 이용해 탐색할 수 있습니다.

## 초급(Basics)

이 단원은 Rust의 기본 문법과 의미를 순차적으로 설명한 것입니다. 개별 단원별로 Rust 문법의각 부분을 담고 있습니다.

여러분이 "초급"을 읽고 나면, Rust에 대해 더 배우기 위한 기초가 쌓이고, 아주 간단한 프로그램을 작성할 수 있을 것입니다.

## 중급(Intermediate)

이 단원은 self-contained 개별 챕터들로 구성되어 있습니다. 이 단원들은 세부적인 주제에 초점을 맞추고 있고, 어떤 순서로 읽어도 상관없습니다.

여러분들이 "중급"을 읽고 나면, Rust의 이해가 탄탄해지고, 대부분의 Rust 코드를 이해할 수 있고, 더 복잡한 프로그램을 작성할 수 있을 것입니다.

## Unstable

"중급"과 비슷하게 이 단원은 지극히 개인적이고, 깊은 주제를 다루있고, 단원들 사이에 서로 연관이 없어 어떤 순서로 읽어도 상관없습니다.

이 단원은 Rust의 nightly channel 에서 유효한 것들만 포함하고 있습니다
[rust]에 대해 알려줄 것입니다. Rust는 세가지 목표(안전성, 속도, 병행성)에 초점을 맞춘 시스템 프로그래밍 언어입니다. 가비지 컬렉터를 가지지 않고 이 목표들을 지속하고 있습니다. 모든 언어들의 다양한 활용을 만족하는 유용한 언어를 만드는 것은 좋지 않습니다. 다른 언어들에 내포되는 것, 프로그램에 특정 공간과 시간이 필요한 것, 디바이스 드라이버와 운영체제와 같이 낮은 레벨의 코드를 작성하는 것. 현존 언어들에, 모든 데이터 경합을 제거하며, 실행 중 부하가 발생하지 않도록 컴파일 중 다양한 안전성 확인을 가지는 영역에 초점을 맞춰 발전시킵니다. 또한 Rust는 추상화들 중 어떤것들은 고수준의 언어의 추상화의 느낌이 나는 것에도 불구하고 ‘비용없는 추상화’를 이루는데 초점을 두고 있습니다. 그럼에도, Rust는 여전히 저수준 언어에서 하는 것같은 정밀한 제어를 허용합니다.

[rust]: http://rust-lang.org

“Rust 프로그래밍 언어”는 일곱 단원으로 구분됩니다. 이 소개는 첫번째 단원입니다. 다음 단원들입니다.

* [시작하기(Getting started)][gs] - Rust 개발을 위한 컴퓨터 환경 구축.
* [Rust 배우기(Learn Rust)][lr] - 작은 프로젝트를 통해 Rust 프로그래밍을 배움.
* [효과적인 Rust(Effective Rust)][er] - 훌륭한 Rust 코드를 작성하기 위한 더 높은 수준의 개념들.
* [문법과 의미(Syntax and Semantics)][ss] - Each bit of Rust, broken down into small chunks.
* [실험적 Rust(Nightly Rust)][nr] - 아직 안정적인 빌드에 포함되지 않은 최신 기능들.
* [용어 해설(Glossary)][gl] - 책에서 사용된 용어들의 참조.
* [학문적 연구(Academic Research)][ar] - Rust에 영향을 준 문헌.

[gs]: getting-started.html
[lr]: learn-rust.html
[er]: effective-rust.html
[ss]: syntax-and-semantics.html
[nr]: nightly-rust.html
[gl]: glossary.html
[ar]: academic-research.html

After reading this introduction, you’ll want to dive into either ‘Learn Rust’
or ‘Syntax and Semantics’, depending on your preference: ‘Learn Rust’ if you
want to dive in with a project, or ‘Syntax and Semantics’ if you prefer to
start small, and learn a single concept thoroughly before moving onto the next.
Copious cross-linking connects these parts together.

### Contributing

The source files from which this book is generated can be found on Github:
[github.com/rust-lang/rust/tree/master/src/doc/trpl](https://github.com/rust-lang/rust/tree/master/src/doc/trpl)

## A brief introduction to Rust

Is Rust a language you might be interested in? Let’s examine a few small code
samples to show off a few of its strengths.

The main concept that makes Rust unique is called ‘ownership’. Consider this
small example:

```rust
fn main() {
let mut x = vec!["Hello", "world"];
}
```

This program makes a [variable binding][var] named `x`. The value of this
binding is a `Vec`, a ‘vector’, that we create through a [macro][macro]
defined in the standard library. This macro is called `vec`, and we invoke
macros with a `!`. This follows a general principle of Rust: make things
explicit. Macros can do significantly more complicated things than function
calls, and so they’re visually distinct. The `!` also helps with parsing,
making tooling easier to write, which is also important.

We used `mut` to make `x` mutable: bindings are immutable by default in Rust.
We’ll be mutating this vector later in the example.

It’s also worth noting that we didn’t need a type annotation here: while Rust
is statically typed, we didn’t need to explicitly annotate the type. Rust has
type inference to balance out the power of static typing with the verbosity of
annotating types.

Rust prefers stack allocation to heap allocation: `x` is placed directly on the
stack. However, the `Vec` type allocates space for the elements of the
vector on the heap. If you’re not familiar with this distinction, you can
ignore it for now, or check out [‘The Stack and the Heap’][heap]. As a systems
programming language, Rust gives you the ability to control how your memory is
allocated, but when we’re getting started, it’s less of a big deal.

[var]: variable-bindings.html
[macro]: macros.html
[heap]: the-stack-and-the-heap.html

Earlier, we mentioned that ‘ownership’ is the key new concept in Rust. In Rust
parlance, `x` is said to ‘own’ the vector. This means that when `x` goes out of
scope, the vector’s memory will be de-allocated. This is done deterministically
by the Rust compiler, rather than through a mechanism such as a garbage
collector. In other words, in Rust, you don’t call functions like `malloc` and
`free` yourself: the compiler statically determines when you need to allocate
or deallocate memory, and inserts those calls itself. To err is to be human,
but compilers never forget.

Let’s add another line to our example:

```rust
fn main() {
let mut x = vec!["Hello", "world"];

let y = &x[0];
}
```

We’ve introduced another binding, `y`. In this case, `y` is a ‘reference’ to
the first element of the vector. Rust’s references are similar to pointers in
other languages, but with additional compile-time safety checks. References
interact with the ownership system by [‘borrowing’][borrowing] what they point
to, rather than owning it. The difference is, when the reference goes out of
scope, it will not deallocate the underlying memory. If it did, we’d
de-allocate twice, which is bad!

[borrowing]: references-and-borrowing.html

Let’s add a third line. It looks innocent enough, but causes a compiler error:

```rust,ignore
fn main() {
let mut x = vec!["Hello", "world"];

let y = &x[0];

x.push("foo");
}
```

`push` is a method on vectors that appends another element to the end of the
vector. When we try to compile this program, we get an error:

```text
error: cannot borrow `x` as mutable because it is also borrowed as immutable
x.push("foo");
^
note: previous borrow of `x` occurs here; the immutable borrow prevents
subsequent moves or mutable borrows of `x` until the borrow ends
let y = &x[0];
^
note: previous borrow ends here
fn main() {

}
^
```

Whew! The Rust compiler gives quite detailed errors at times, and this is one
of those times. As the error explains, while we made our binding mutable, we
still cannot call `push`. This is because we already have a reference to an
element of the vector, `y`. Mutating something while another reference exists
is dangerous, because we may invalidate the reference. In this specific case,
when we create the vector, we may have only allocated space for three elements.
Adding a fourth would mean allocating a new chunk of memory for all those elements,
copying the old values over, and updating the internal pointer to that memory.
That all works just fine. The problem is that `y` wouldn’t get updated, and so
we’d have a ‘dangling pointer’. That’s bad. Any use of `y` would be an error in
this case, and so the compiler has caught this for us.

So how do we solve this problem? There are two approaches we can take. The first
is making a copy rather than using a reference:

```rust
fn main() {
let mut x = vec!["Hello", "world"];

let y = x[0].clone();

x.push("foo");
}
```

Rust has [move semantics][move] by default, so if we want to make a copy of some
data, we call the `clone()` method. In this example, `y` is no longer a reference
to the vector stored in `x`, but a copy of its first element, `"Hello"`. Now
that we don’t have a reference, our `push()` works just fine.

[move]: move-semantics.html

If we truly want a reference, we need the other option: ensure that our reference
goes out of scope before we try to do the mutation. That looks like this:

```rust
fn main() {
let mut x = vec!["Hello", "world"];

{
let y = &x[0];
}

x.push("foo");
}
```

We created an inner scope with an additional set of curly braces. `y` will go out of
scope before we call `push()`, and so we’re all good.

This concept of ownership isn’t just good for preventing dangling pointers, but an
entire set of related problems, like iterator invalidation, concurrency, and more
.