{"id":6516,"date":"2022-10-01T15:56:51","date_gmt":"2022-10-01T06:56:51","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6516"},"modified":"2022-10-02T19:46:01","modified_gmt":"2022-10-02T10:46:01","slug":"rust-hello-world","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6516","title":{"rendered":"Rust &#8211; \uc2dc\uc791\ud558\uae30"},"content":{"rendered":"<h1>Rust &#8211; \uc2dc\uc791\ud558\uae30<\/h1>\n<h2>Hello World<\/h2>\n<pre><code class=\"language-rust\">fn main() {\n    println!(&quot;Hello, world!&quot;);\n}<\/code><\/pre>\n<h2>\ubcc0\uc218<\/h2>\n<h3>\ubcc0\uc218\uc758 \ubd88\ubcc0\uc131<\/h3>\n<p>\ubcc0\uc218\ub294 \ub514\ud3f4\ud2b8\ub85c \ubd88\ubcc0\uc774\ub2e4.(immutable)<br \/>\n\uac00\ubcc0\ubcc0\uc218\ub85c \ub9cc\ub4e4\ub824\uba74 mut \ub97c \ubd99\uc5ec\uc57c \ud55c\ub2e4.(mutable)<\/p>\n<pre><code class=\"language-rust\">fn main() {\n    let i = 10;\n    let j : i32 = 20;\n    let mut k = 30;\n\n    println!(&quot;k = {}&quot;, k);\n\n    k = 40;\n\n    println!(&quot;i = {}, j = {}, k = {}&quot;, i, j, k);\n}<\/code><\/pre>\n<h3>tuple<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let (i, j) = (10, 20);\n\n    println!(&quot;i * j = {}&quot;, i * j);\n}<\/code><\/pre>\n<h3>\ubc30\uc5f4(array)<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let lst = [1, 2, 3];\n\n    println!(&quot;size = {}, first = {}&quot;, lst.len(), lst[0]);\n\n    for i in lst {\n        println!(&quot;{}&quot;, i);\n    }\n}<\/code><\/pre>\n<h3>String<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let mut s = String::new();\n    s.push_str(&quot;hello&quot;);\n    s.push_str(&quot;, world!&quot;);\n    println!(&quot;{}&quot;, s);\n\n    let mut s = String::from(&quot;hello&quot;);\n    s.push_str(&quot;, world!&quot;);\n    println!(&quot;{}&quot;, s);\n}<\/code><\/pre>\n<h3>\uce90\uc2a4\ud305<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let decimal = 65.4321_f32;\n\n    \/\/ Explicit conversion\n    let integer = decimal as u8;\n    let character = integer as char;\n\n    println!(&quot;{}, {}, {}&quot;, decimal, integer, character)\n}<\/code><\/pre>\n<h2>\uc81c\uc5b4\ubb38<\/h2>\n<h3>if<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let i = 10;\n\n    if i &lt;= 5 {\n        println!(&quot;i \ub294 5 \uc774\ud558\uc774\ub2e4.&quot;);\n    } else if i &lt;= 10 {\n        println!(&quot;i \ub294 10 \uc774\ud558\uc774\ub2e4.&quot;);\n    } else {\n        println!(&quot;i \ub294 10 \ubcf4\ub2e4 \ud06c\ub2e4.&quot;);\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-rust\">fn main() {\n    let i = 10;\n    let j = if i != 5 {\n        5\n    } else {\n        6\n    };\n\n    println!(&quot;j = {}&quot;, j);\n}<\/code><\/pre>\n<h3>loop, while, for<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let mut i = 1;\n\n    loop {\n        println!(&quot;i = {}&quot;, i);\n\n        if i &gt;= 10 {\n            break;\n        } else {\n            i = i + 1;\n        }\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-rust\">fn main() {\n    let mut i = 1;\n\n    while i &lt;= 10 {\n        println!(&quot;i = {}&quot;, i);\n        i = i + 1;\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-rust\">fn main() {\n    for i in 1..11 {\n        println!(&quot;i = {}&quot;, i);\n    }\n}<\/code><\/pre>\n<h3>switch(X), match(O)<\/h3>\n<p>rust \uc5d0\uc11c\ub294 switch \ubcf4\ub2e4 \ub354 \uac15\ub825\ud55c match \ub97c \uc81c\uacf5\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-rust\">use std::cmp::Ordering;\n\nfn main() {\n    let i = 10;\n    let j = 20;\n\n    match i.cmp(&amp;j) {\n        Ordering::Less    =&gt; println!(&quot;\uc791\uc2b5\ub2c8\ub2e4.&quot;),\n        Ordering::Greater =&gt; println!(&quot;\ud07d\ub2c8\ub2e4.&quot;),\n        Ordering::Equal   =&gt; {\n            println!(&quot;OK!&quot;);\n        },\n    }\n}<\/code><\/pre>\n<h2>\ud568\uc218<\/h2>\n<h3>\uae30\ucd08<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    println!(&quot;\uba54\uc778 \ud568\uc218&quot;);\n\n    sub_function();\n}\n\nfn sub_function() {\n    println!(&quot;\uc11c\ube0c \ud568\uc218&quot;);\n}<\/code><\/pre>\n<h3>\ud30c\ub77c\ubbf8\ud130 \uc804\ub2ec<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    sub_function(5, 6);\n}\n\nfn sub_function(x: i32, y: i32) {\n    println!(&quot;{} * {} = {}&quot;, x, y, x * y);\n}<\/code><\/pre>\n<h3>\ub9ac\ud134\uac12<\/h3>\n<p>return \ud0a4\uc6cc\ub4dc\ub97c \uc0ac\uc6a9\ud560 \uc218\ub3c4 \uc788\uace0, \uc544\ub798\ucc98\ub7fc \ub9c8\uc9c0\ub9c9 \ub77c\uc778\uc5d0 \ud45c\ud604\uc2dd\uc744 \ub9ac\ud134\uac12\uc73c\ub85c \uc4f8 \uc218\ub3c4 \uc788\ub2e4.<\/p>\n<p>\ud45c\ud604\uc2dd\uc744 \ub9ac\ud134\uac12\uc73c\ub85c \uc4f8 \ub54c\ub294 \uc138\ubbf8\ucf5c\ub860(;)\uc744 \uc0dd\ub7b5\ud574\uc57c \ud55c\ub2e4.<\/p>\n<pre><code class=\"language-rust\">fn main() {\n    println!(&quot;5 * 6 = {}&quot;, sub_function(5, 6));\n}\n\nfn sub_function(x: i32, y: i32) -&gt; i32 {\n    x * y\n}<\/code><\/pre>\n<h2>\uc18c\uc720\uad8c(Ownership)<\/h2>\n<p>rust \uc758 \ud575\uc2ec \uae30\ub2a5\uc774 \ubc14\ub85c \uc18c\uc720\uad8c\uc774\ub2e4.<\/p>\n<h3>\uc18c\uc720\uad8c \uaddc\uce59<\/h3>\n<blockquote>\n<ol>\n<li>\uac01\uac01\uc758 \uac12\uc740 \ud574\ub2f9 \uac12\uc758 \uc624\ub108(owner)\ub77c\uace0 \ubd88\ub9ac\uc6b0\ub294 \ud558\ub098\uc758 \ubcc0\uc218\ub97c \uac16\ub294\ub2e4.<\/li>\n<li>\ud55c\ubc88\uc5d0 \ub531 \ud558\ub098\uc758 \uc624\ub108\ub9cc \uc874\uc7ac\ud560 \uc218 \uc788\ub2e4.<\/li>\n<li>\uc624\ub108\uac00 \uc2a4\ucf54\ud504 \ubc16\uc73c\ub85c \ubc97\uc5b4\ub098\ub294 \ub54c, \uac12\uc740 \ubc84\ub824\uc9c4\ub2e4(dropped).<\/li>\n<\/ol>\n<\/blockquote>\n<h3>\ub531 \ud558\ub098\uc758 \uc624\ub108(\uc18c\uc720\uad8c \uc774\uc804)<\/h3>\n<p>\uc18c\uc720\uad8c\uc774 \uc774\uc804\ub418\uba74 \uc774\uc804 \ubcc0\uc218\ub294 \ub354\uc774\uc0c1 \uc0ac\uc6a9\ud560 \uc218 \uc5c6\ub2e4.<\/p>\n<p>\uc18c\uc720\uad8c \uc774\uc804 \ubc29\uc2dd\uc740 \ubcc0\uc218\uc785\ub825, \ud568\uc218 \ud30c\ub77c\ubbf8\ud130 \uc804\ub2ec, \ud568\uc218 \ub9ac\ud134\uac12\uc758 \ubc29\uc2dd\uc774 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-rust\">fn main() {\n    let s1 = String::from(&quot;hello&quot;);\n    let s2 = s1;\n\n    println!(&quot;{}, world!&quot;, s2); \/\/ ok\n    \/\/ println!(&quot;{}, world!&quot;, s1); \/\/ error\n}<\/code><\/pre>\n<h3>\ubcf5\uc0ac<\/h3>\n<pre><code class=\"language-rust\">fn main() {\n    let s1 = String::from(&quot;hello&quot;);\n    let s2 = s1.clone();\n\n    println!(&quot;{}, world!&quot;, s2); \/\/ ok\n    println!(&quot;{}, world!&quot;, s1); \/\/ ok\n}<\/code><\/pre>\n<h3>\ud3ec\uc778\ud130(X), \ucc38\uc870\uc790(O)<\/h3>\n<p>rust \ub294 \uad00\ub9ac\ud558\uae30 \ud798\ub4e0 \ud3ec\uc778\ud130\ub97c \ub300\uc2e0\ud574\uc11c, \ucc38\uc870\uc790\ub97c \uc774\uc6a9\ud55c\ub2e4.<\/p>\n<h4>\ucc38\uc870\uc790\ub294 \uc18c\uc720\uad8c \uc774\uc804\uc774 \uc5c6\ub2e4<\/h4>\n<p>\ucc38\uc870\uc790(&amp;) \ub97c \uc774\uc6a9\ud574 \uc18c\uc720\uad8c \uc774\uc804\uc5c6\uc774 \uac12\uc744 \uc804\ub2ec\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-rust\">fn main() {\n    let s1 = String::from(&quot;hello&quot;);\n    let len = calculate_length(&amp;s1);\n    println!(&quot;The length of &#039;{}&#039; is {}.&quot;, s1, len);\n}\n\nfn calculate_length(s: &amp;String) -&gt; usize {\n    s.len()\n}<\/code><\/pre>\n<h4>\uac00\ubcc0 \ucc38\uc870\uc790(Mutable References)<\/h4>\n<p>\ucc38\uc870\uc790 \uc5ed\uc2dc \ubd88\ubcc0\uc774 \ub514\ud3f4\ud2b8\uc774\ub2e4.<\/p>\n<p>\ubcc0\uacbd \uac00\ub2a5\ud55c \ucc38\uc870\uc790\ub97c \uc774\uc6a9\ud558\ub824\uba74 <code>&amp;mut<\/code> \ub97c \ubd99\uc5ec\uc57c \ud55c\ub2e4.<\/p>\n<pre><code class=\"language-rust\">fn main() {\n    let mut s = String::from(&quot;hello&quot;);\n    change(&amp;mut s);\n    println!(&quot;{}&quot;, s)\n}\n\nfn change(some_string: &amp;mut String) {\n    some_string.push_str(&quot;, world&quot;);\n}<\/code><\/pre>\n<h4>\ucc38\uc870\uc790\uc758 \uaddc\uce59<\/h4>\n<p>\ub458 \uc911 \ud55c\uac00\uc9c0\uc758 \ucc38\uc870\uc790\ub9cc \uac00\uc9c8 \uc218 \uc788\ub2e4.<\/p>\n<ol>\n<li>\uac00\ubcc0 \ucc38\uc870\uc790 \ub2e8 \ud55c\uac1c<\/li>\n<li>\uc5ec\ub7ec \uac1c\uc758 \ubd88\ubcc0 \ucc38\uc870\uc790<\/li>\n<\/ol>\n<h4>\uc2ac\ub77c\uc774\uc2a4(Slices)<\/h4>\n<p>\uceec\ub809\uc158\uc758 \uc77c\ubd80\uc5d0 \ub300\ud55c \ucc38\uc870\ub97c \uc2ac\ub77c\uc774\uc2a4\ub77c\uace0 \ud55c\ub2e4.<\/p>\n<p>TODO<\/p>\n<h2>\uad6c\uc870\uccb4<\/h2>\n<h3>\uae30\ubcf8<\/h3>\n<pre><code class=\"language-rust\">struct User {\n    username: String,\n    email: String,\n    sign_in_count: u64,\n    active: bool,\n}<\/code><\/pre>\n<p>\ud544\ub4dc \uc21c\uc11c\ub294 \ub2ec\ub77c\ub3c4 \uc0c1\uad00\uc5c6\ub2e4.<\/p>\n<pre><code class=\"language-rust\">let mut user1 = User {\n    email: String::from(&quot;someone@example.com&quot;),\n    username: String::from(&quot;someusername123&quot;),\n    active: true,\n    sign_in_count: 1,\n};<\/code><\/pre>\n<pre><code class=\"language-rust\">user1.email = String::from(&quot;skyer9@gmail.com&quot;);\nprintln!(&quot;{}&quot;, user1.username);<\/code><\/pre>\n<p>\uae30\uc874 \uad6c\uc870\uccb4\uc758 \uac12\uc744 \uc774\uc6a9\ud574 \uc0c8 \uad6c\uc870\uccb4\ub97c \uc0dd\uc131\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-rust\">let user2 = User {\n    username: String::from(&quot;anotherusername567&quot;),\n    ..user1\n};<\/code><\/pre>\n<h3>tuple \uad6c\uc870\uccb4<\/h3>\n<pre><code class=\"language-rust\">struct Color(i32, i32, i32);\nstruct Point(i32, i32, i32);\n\nlet black = Color(0, 0, 0);\nlet origin = Point(0, 0, 0);<\/code><\/pre>\n<h2>\ubaa8\ub4c8<\/h2>\n<p>main.rs<\/p>\n<pre><code class=\"language-rust\">pub mod file1;\n\nfn main() {\n    file1::func(&quot;Lee&quot;);\n}<\/code><\/pre>\n<p>file1.rs<\/p>\n<pre><code class=\"language-rust\">pub fn func(name: &amp;str) {\n    println!(&quot;Hello {}&quot;, name.to_string());\n}<\/code><\/pre>\n<h2>\uba54\ubaa8\ub9ac \uad00\ub9ac<\/h2>\n<h3><code>Box&lt;T&gt;<\/code><\/h3>\n<ol>\n<li>\ucef4\ud30c\uc77c \ud0c0\uc784\uc5d0 \ud06c\uae30\ub97c \uc54c \uc218 \uc5c6\ub294 \ud0c0\uc785\uc744 \uc800\uc7a5\ud560 \uc218 \uc788\ub2e4.<\/li>\n<li>\ucee4\ub2e4\ub780 \ub370\uc774\ud0c0\uc758 \uc18c\uc720\uad8c \uc774\uc804\uc2dc \ubcf5\uc0ac\uac00 \ubc1c\uc0dd\ud558\uc9c0 \uc54a\ub294\ub2e4.<\/li>\n<\/ol>\n<h2>generic<\/h2>\n<h3>\uae30\ubcf8<\/h3>\n<pre><code class=\"language-rust\">fn show&lt;T&gt;(x: T) -&gt; T {\n    x\n}\n\nfn main() {\n    println!(&quot;{}&quot;, show(10.0));\n}<\/code><\/pre>\n<pre><code class=\"language-rust\">struct Point&lt;T, U&gt; {\n    x: T,\n    y: U,\n}\n\nfn main() {\n    let p = Point {\n        x: 1, y: 2.0\n    };\n\n    println!(&quot;{}, {}&quot;, p.x, p.y);\n}<\/code><\/pre>\n<p>\uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud55c\ub2e4.<br \/>\n\ud2b8\ub808\uc787(trait) \uc5d0\uc11c \uc5d0\ub7ec\ub97c \ubc29\uc9c0\ud558\ub294 \ubc29\ubc95\uc744 \uc124\uba85\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-rust\">\/\/ error\nfn multiply&lt;T&gt;(x: T, y: T) -&gt; T {\n    x * y\n}<\/code><\/pre>\n<h3>\ud2b8\ub808\uc787(trait)<\/h3>\n<h4>\uad6c\uc870\uccb4\uc640 \ud2b8\ub808\uc787(trait)<\/h4>\n<p>Java interface \uc640 \uc720\uc0ac\ud558\ub2e4.<\/p>\n<pre><code class=\"language-rust\">trait Animal {\n    fn custom_bark(&amp;self);\n\n    fn common_bark(&amp;self) {\n        println!(&quot;Common Bark&quot;);\n    }\n}\n\nstruct Dog {\n    pomeranian : String,\n    poodle : String,\n    dashs_hund : String,\n}\n\nimpl Animal for Dog {\n    fn custom_bark(&amp;self) {\n        println!(&quot;Pomeranian Bark : {}&quot;, self.pomeranian);\n        println!(&quot;Poodle Bark : {}&quot;, self.poodle);\n        println!(&quot;Dashshund Bark : {}&quot;, self.dashs_hund);\n    }\n}\n\nfn main() {\n    let dog = Dog{\n        pomeranian : String::from(&quot;\ub091\ub091&quot;),\n        poodle : String::from(&quot;\uba4d\uba4d&quot;),\n        dashs_hund : String::from(&quot;\ub315\ub315&quot;)\n    };\n\n    dog.common_bark();\n    dog.custom_bark();\n}<\/code><\/pre>\n<h4>generic \uacfc \ud2b8\ub808\uc787(trait)<\/h4>\n<pre><code class=\"language-rust\">trait Animal {\n    fn custom_bark(&amp;self);\n\n    fn common_bark(&amp;self) {\n        println!(&quot;Common Bark&quot;);\n    }\n}\n\nstruct Dog {\n    pomeranian : String,\n    poodle : String,\n    dashs_hund : String,\n}\n\nstruct Cat {\n    ragdoll: String,\n    russian_blue: String,\n    manx: String,\n}\n\nimpl Animal for Dog {\n    fn custom_bark(&amp;self) {\n        println!(&quot;Pomeranian Bark : {}&quot;, self.pomeranian);\n        println!(&quot;Poodle Bark : {}&quot;, self.poodle);\n        println!(&quot;Dashshund Bark : {}&quot;, self.dashs_hund);\n    }\n}\n\nimpl Animal for Cat {\n    fn custom_bark(&amp;self) {\n        println!(&quot;Cat Bark&quot;);\n        println!(&quot;Ragdoll Bark : {}&quot;, self.ragdoll);\n        println!(&quot;RussianBlue Bark : {}&quot;, self.russian_blue);\n        println!(&quot;Manx Bark : {}&quot;, self.manx);\n    }\n}\n\nfn animal_bark&lt;T : Animal&gt;(animal : T){\n    animal.custom_bark();\n}\n\nfn main() {\n    let dog = Dog{\n        pomeranian : String::from(&quot;\ub091\ub091&quot;),\n        poodle : String::from(&quot;\uba4d\uba4d&quot;),\n        dashs_hund : String::from(&quot;\ub315\ub315&quot;)\n    };\n\n    let cat = Cat{\n        ragdoll: String::from(&quot;\ub0d0\uc639&quot;),\n        russian_blue: String::from(&quot;\uceac\uc545&quot;),\n        manx: String::from(&quot;\uafb9\uafb9&quot;)\n    };\n\n    animal_bark(dog);\n    animal_bark(cat);\n}<\/code><\/pre>\n<h4>generic \uacfc \ud2b8\ub808\uc787(trait) \uc5ec\ub7ec\uac1c<\/h4>\n<p>\uc5ec\ub7ec\uac1c\uc758 \ud2b8\ub808\uc787\uc744 \ubc1b\uc73c\ub824\uba74 \uc544\ub798\ucc98\ub7fc <code>+<\/code> \ub85c \ucd94\uac00\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-rust\">fn some_function&lt;T: Display + Clone, U: Clone + Debug&gt;(t: T, u: U) -&gt; i32 {\n    \/\/ ......\n}<\/code><\/pre>\n<p>\ud2b8\ub808\uc787\uc744 <code>where<\/code> \ucabd\uc73c\ub85c \uc62e\uae38 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-rust\">fn some_function&lt;T, U&gt;(t: T, u: U) -&gt; i32\n    where T: Display + Clone,\n          U: Clone + Debug\n{\n    \/\/ ......\n}<\/code><\/pre>\n<h4>multiply() \uc624\ub958 \uc218\uc815<\/h4>\n<pre><code class=\"language-rust\">use std::ops::Mul;\n\nfn multiply&lt;T: Mul&lt;Output=T&gt;&gt;(x: T, y: T) -&gt; T {\n    x * y\n}\n\nfn main() {\n    println!(&quot;{}&quot;, multiply(5, 6));\n}<\/code><\/pre>\n<h2>\uad6c\uad6c\ub2e8<\/h2>\n<pre><code class=\"language-rust\">fn main() {\n    for i in 2..10 {\n        for j in 1..10 {\n            println!(&quot;{} x {} = {}&quot;, i, j, i * j);\n        }\n    }\n}<\/code><\/pre>\n<h2>\uc785\ub825\ubc1b\uae30<\/h2>\n<p><code>&amp;mut guess<\/code><\/p>\n<p>&amp; \ub294 \ucc38\uc870\uc790\uc774\ub2e4.<br \/>\n\ucc38\uc870\ub294 \ub514\ud3f4\ud2b8\ub85c \ubd88\ubcc0\uc774\ubbc0\ub85c mut \ub97c \ubd99\uc5ec\uc57c \ud55c\ub2e4.<\/p>\n<pre><code class=\"language-rust\">use std::io;\nuse std::io::Write;\n\nfn main() {\n    print!(&quot;\uc22b\uc790\ub97c \uc785\ub825\ud558\uc138\uc694[1-100]: &quot;);\n    io::stdout().flush().unwrap();\n\n    let mut guess = String::new();\n\n    io::stdin()\n        .read_line(&amp;mut guess)\n        .expect(&quot;\uc798\ubabb\ub41c \uac12\uc785\ub2c8\ub2e4.&quot;);\n\n    println!(&quot;\uc785\ub825\uac12: {}&quot;, guess);\n}<\/code><\/pre>\n<h2>\ub79c\ub364 \uc22b\uc790 \uc0dd\uc131<\/h2>\n<p>Cargo.toml<\/p>\n<pre><code class=\"language-toml\">[dependencies]\n\nrand = &quot;0.8.5&quot;<\/code><\/pre>\n<pre><code class=\"language-rust\">extern crate rand;\n\nuse std::io;\nuse std::io::Write;\nuse std::cmp::Ordering;\nuse rand::Rng;\n\nfn main() {\n    println!(&quot;\uc22b\uc790 \ub9de\ucd94\uae30!&quot;);\n\n    let secret_number = rand::thread_rng().gen_range(1..101);\n\n    print!(&quot;\uc0dd\uac01\ud558\ub294 \uc22b\uc790\ub97c \uc785\ub825\ud558\uc138\uc694[1-100]: &quot;);\n    io::stdout().flush().unwrap();\n\n    let mut guess = String::new();\n\n    io::stdin()\n        .read_line(&amp;mut guess)\n        .expect(&quot;\uc798\ubabb\ub41c \uac12\uc785\ub2c8\ub2e4.&quot;);\n\n    let guess: u32 = guess.trim().parse()\n        .expect(&quot;\uc22b\uc790\uac00 \uc544\ub2d9\ub2c8\ub2e4.&quot;);\n\n    println!(&quot;\ub79c\ub364\uac12: {}&quot;, secret_number);\n    println!(&quot;\uc785\ub825\uac12: {}&quot;, guess);\n\n    match guess.cmp(&amp;secret_number) {\n        Ordering::Less    =&gt; println!(&quot;\ub108\ubb34 \uc791\uc2b5\ub2c8\ub2e4.&quot;),\n        Ordering::Greater =&gt; println!(&quot;\ub108\ubb34 \ud07d\ub2c8\ub2e4.&quot;),\n        Ordering::Equal   =&gt; println!(&quot;\ube59\uace0!&quot;),\n    }\n}<\/code><\/pre>\n<h2>\uc22b\uc790 \ub9de\ucd94\uae30<\/h2>\n<pre><code class=\"language-rust\">extern crate rand;\n\nuse std::io;\nuse std::io::Write;\nuse std::cmp::Ordering;\nuse rand::Rng;\n\nfn main() {\n    println!(&quot;\uc22b\uc790 \ub9de\ucd94\uae30!&quot;);\n\n    let secret_number = rand::thread_rng().gen_range(1..101);\n\n    loop {\n        print!(&quot;\uc0dd\uac01\ud558\ub294 \uc22b\uc790\ub97c \uc785\ub825\ud558\uc138\uc694[1-100]: &quot;);\n        io::stdout().flush().unwrap();\n\n        let mut guess = String::new();\n\n        io::stdin()\n            .read_line(&amp;mut guess)\n            .expect(&quot;\uc798\ubabb\ub41c \uac12\uc785\ub2c8\ub2e4.&quot;);\n\n        let guess: u32 = guess.trim().parse()\n            .expect(&quot;\uc22b\uc790\uac00 \uc544\ub2d9\ub2c8\ub2e4.&quot;);\n\n        match guess.cmp(&amp;secret_number) {\n            Ordering::Less    =&gt; println!(&quot;\ub108\ubb34 \uc791\uc2b5\ub2c8\ub2e4.&quot;),\n            Ordering::Greater =&gt; println!(&quot;\ub108\ubb34 \ud07d\ub2c8\ub2e4.&quot;),\n            Ordering::Equal   =&gt; {\n                println!(&quot;\ube59\uace0!&quot;);\n                break;\n            },\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Rust &#8211; \uc2dc\uc791\ud558\uae30 Hello World fn main() { println!(&quot;Hello, world!&quot;); } \ubcc0\uc218 \ubcc0\uc218\uc758 \ubd88\ubcc0\uc131 \ubcc0\uc218\ub294 \ub514\ud3f4\ud2b8\ub85c \ubd88\ubcc0\uc774\ub2e4.(immutable) \uac00\ubcc0\ubcc0\uc218\ub85c \ub9cc\ub4e4\ub824\uba74 mut \ub97c \ubd99\uc5ec\uc57c \ud55c\ub2e4.(mutable) fn main() { let i = 10; let j : i32 = 20; let mut k = 30; println!(&quot;k = {}&quot;, k); k = 40; println!(&quot;i = {}, j = {}, k\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=6516\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[],"class_list":["post-6516","post","type-post","status-publish","format-standard","hentry","category-rust-language"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6516"}],"version-history":[{"count":24,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6516\/revisions"}],"predecessor-version":[{"id":6540,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6516\/revisions\/6540"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}