Skip to content
Snippets Groups Projects
Commit dd009bb2 authored by Alfex4936's avatar Alfex4936
Browse files

Update chapter 1

parent 878a13d4
No related branches found
No related tags found
No related merge requests found
Pipeline #6190 passed
...@@ -53,7 +53,7 @@ let my_literal: &'static str = "안녕하세요!"; ...@@ -53,7 +53,7 @@ let my_literal: &'static str = "안녕하세요!";
<p>이러한 방식을 사용함으로써, Rust는 안전성과 소유권을 보장할 수 있습니다.</p> <p>이러한 방식을 사용함으로써, Rust는 안전성과 소유권을 보장할 수 있습니다.</p>
<pre><code class="rust">// 예제 2 <pre><code class="rust">// 예제 2
let full_name = "홍길동"; let full_name = "홍길동";
let first_name: &str = &full_name[..2]; // "홍길"만 참조</code></pre> let first_name: &str = &full_name[..6]; // "홍길"만 참조, 한글 3bytes, 알파벳 1byte</code></pre>
<hr /> <hr />
<p><code>String</code>: 이 타입은 가변하며 크기가 변경될 수 있는 문자열입니다.</p> <p><code>String</code>: 이 타입은 가변하며 크기가 변경될 수 있는 문자열입니다.</p>
<p>String은 <code>Heap</code>에 저장되며, 필요에 따라 크기를 늘이거나 줄일 수 있습니다.</p> <p>String은 <code>Heap</code>에 저장되며, 필요에 따라 크기를 늘이거나 줄일 수 있습니다.</p>
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
<h1>Basic Type Conversion</h1> <h1>Basic Type Conversion</h1>
<p>Rust는 숫자 변수 타입에 대해 알고 있어야하며, <code>u8</code><code>u32</code>로 쉽게 사용할 수 없습니다.</p> <p>Rust는 숫자 변수 타입에 대해 알고 있어야하며, <code>u8</code><code>u32</code>로 쉽게 사용할 수 없습니다.</p>
<p>다행히 Rust는 <strong>as</strong> 키워드를 사용하여 숫자형을 쉽게 변환할 수 있습니다.</p> <p>다행히 Rust는 <strong>as</strong> 키워드를 사용하여 숫자형을 쉽게 변환할 수 있습니다.</p>
<p>또는 <code>parse</code>를 자주 사용합니다.</p>
<pre><code class="rust">let my_string = "42"; let my_integer = my_string.parse::<i32>().unwrap(); // double colon op, ::<i32> syntax tells the compiler to parse the string as an i32 type</code></pre>
<div class="bottomnav"> <div class="bottomnav">
<span class="back"><a href="11_ko.html" rel="prev">❮ 이전</a></span> <span class="back"><a href="11_ko.html" rel="prev">❮ 이전</a></span>
<span class="next"><a href="13_ko.html" rel="next">다음 ❯</a></span> <span class="next"><a href="13_ko.html" rel="next">다음 ❯</a></span>
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
0 => println!("숫자는 영입니다"), 0 => println!("숫자는 영입니다"),
1 => println!("숫자는 일입니다"), 1 => println!("숫자는 일입니다"),
42 => println!("인생, 우주, 그리고 모든 것에 대한 답"), 42 => println!("인생, 우주, 그리고 모든 것에 대한 답"),
_ => println!("숫자는 다른 입니다"), _ => println!("다른 숫자입니다"),
} }
}</code></pre> }</code></pre>
<p>여기서는 number 변수의 값을 여러 패턴과 비교합니다.</p> <p>여기서는 number 변수의 값을 여러 패턴과 비교합니다.</p>
...@@ -60,7 +60,9 @@ ...@@ -60,7 +60,9 @@
} }
} }
fn main() { fn main() {
let age = 25; let age = 65;
classify_age(age);
let age = 30;
classify_age(age); classify_age(age);
}</code></pre> }</code></pre>
<p>이 예제에서는 match 표현식을 사용하여 나이를 그룹으로 분류하고,</p> <p>이 예제에서는 match 표현식을 사용하여 나이를 그룹으로 분류하고,</p>
......
...@@ -192,7 +192,7 @@ ...@@ -192,7 +192,7 @@
let full_name = "홍길동"; let full_name = "홍길동";
let first_name: &str = &full_name[..2]; // "홍길"만 참조 let first_name: &str = &full_name[..6]; // "홍길"만 참조, 한글 3bytes, 알파벳 1byte
%end% %end%
...@@ -276,6 +276,16 @@ ...@@ -276,6 +276,16 @@
다행히 Rust는 **as** 키워드를 사용하여 숫자형을 쉽게 변환할 수 있습니다. 다행히 Rust는 **as** 키워드를 사용하여 숫자형을 쉽게 변환할 수 있습니다.
또는 `parse`를 자주 사용합니다.
%rust%
let my_string = "42";
let my_integer = my_string.parse::<i32>().unwrap();
// double colon op, ::<i32> syntax tells the compiler to parse the string as an i32 type
%end%
- title: Constants - title: Constants
code: >- code: >-
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=const%20PI%3A%20f32%20%3D%203.14159%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20println!(%0A%20%20%20%20%20%20%20%20%22To%20make%20an%20apple%20%7B%7D%20from%20scratch%2C%20you%20must%20first%20create%20a%20universe.%22%2C%0A%20%20%20%20%20%20%20%20PI%0A%20%20%20%20)%3B%0A%7D%0A https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=const%20PI%3A%20f32%20%3D%203.14159%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20println!(%0A%20%20%20%20%20%20%20%20%22To%20make%20an%20apple%20%7B%7D%20from%20scratch%2C%20you%20must%20first%20create%20a%20universe.%22%2C%0A%20%20%20%20%20%20%20%20PI%0A%20%20%20%20)%3B%0A%7D%0A
...@@ -379,7 +389,7 @@ ...@@ -379,7 +389,7 @@
0 => println!("숫자는 영입니다"), 0 => println!("숫자는 영입니다"),
1 => println!("숫자는 일입니다"), 1 => println!("숫자는 일입니다"),
42 => println!("인생, 우주, 그리고 모든 것에 대한 답"), 42 => println!("인생, 우주, 그리고 모든 것에 대한 답"),
_ => println!("숫자는 다른 입니다"), _ => println!("다른 숫자입니다"),
} }
} }
%end% %end%
...@@ -401,7 +411,9 @@ ...@@ -401,7 +411,9 @@
} }
fn main() { fn main() {
let age = 25; let age = 65;
classify_age(age);
let age = 30;
classify_age(age); classify_age(age);
} }
%end% %end%
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment