Skip to content
Snippets Groups Projects
Select Git revision
  • 46f9be8990d831d3defdb09771a65baebdaa0be2
  • main default protected
2 results

index.js

Blame
  • 15_ko.html 5.39 KiB
    <!DOCTYPE html>
        <html lang="ko">
        <head>
            <title>Rust 튜토리얼 - 자기주도프로젝트</title>
    
            <meta charset="UTF-8">
            <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
            <meta content="utf-8" http-equiv="encoding">
            <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"
            <meta name="keywords" content="Rust, Programming, Learning">
            <meta name="description" content="Rust tutorial website based on tour_of_rust">
            <meta name="theme-color" content="#ff6801"/>
            <meta http-equiv="Cache-Control" content="max-age=3600">
            
            <link rel="stylesheet" href="tour.css">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/night-owl.min.css">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.1/css/all.min.css">
            
            <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
            <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
            <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
            <link rel="/manifest" href="./site.webmanifest">
            
            <script src="//unpkg.com/@highlightjs/cdn-assets@11.7.0/highlight.min.js"></script>
    
            <script src="./tour.js" defer></script>
            <!-- <script>hljs.highlightAll();</script> -->
            <script src="./highlight.badge.min.js"></script>
        </head>
        <body>
            <div class="tour">
                <div class="header">
                    <span class="title"><a href="index.html">Rust 튜토리얼</a></span>
                    <span class="nav">
                    <span class="toc"><a href="TOC_ko.html">목차</a></span>
                </div>
                <div class="page">
                <h1>match</h1>
                <p>Rust에서 match 키워드는 패턴 매칭을 위해 사용하고</p>
    <p>값과 일련의 패턴을 비교할 수 있게 해줍니다.</p>
    <p>그리고 첫 번째 일치하는 패턴에 해당하는 코드 블록을 실행합니다.</p>
    <pre><code class="rust">fn main() {
        let number = 42;
    
        match number {
            0 => println!("숫자는 영입니다"),
            1 => println!("숫자는 일입니다"),
            42 => println!("인생, 우주, 그리고 모든 것에 대한 답"),
            _ => println!("숫자는 다른 것입니다"),
        }
    }</code></pre>
    <p>여기서는 number 변수의 값을 여러 패턴과 비교합니다.</p>
    <p><code>_</code> 패턴은 이전 패턴에서 명시적으로 다루지 않은 모든 값을 매치하는 <code>catch-all</code> 패턴입니다.</p>
    <pre><code class="rust">fn classify_age(age: u8) {
        match age {
            0..=12 => println!("어린이"),
            13..=19 => println!("청소년"),
            20..=64 => println!("성인"),
            _ => println!("노인"),
        }
    }
    fn main() {
        let age = 25;
        classify_age(age);
    }</code></pre>
    <p>이 예제에서는 match 표현식을 사용하여 나이를 그룹으로 분류하고,</p>
    <p>나이 변수와 매치하기 위해 범위를 패턴으로 사용합니다.</p>
                <div class="bottomnav">
                    <span class="back"><a href="14_ko.html" rel="prev">❮ 이전</a></span>
                    <span class="next"><a href="16_ko.html" rel="next">다음 ❯</a></span>
                </div>
                </div>
                <div class="code">
                <iframe id="rust-playground" width="100%" src="https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20swap(x%3A%20i32%2C%20y%3A%20i32)%20-%3E%20(i32%2C%20i32)%20%7B%0A%20%20%20%20return%20(y%2C%20x)%3B%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20%2F%2F%20return%20a%20tuple%20of%20return%20values%0A%20%20%20%20let%20result%20%3D%20swap(123%2C%20321)%3B%0A%20%20%20%20println!(%22%7B%7D%20%7B%7D%22%2C%20result.0%2C%20result.1)%3B%0A%0A%20%20%20%20%2F%2F%20destructure%20the%20tuple%20into%20two%20variables%20names%0A%20%20%20%20let%20(a%2C%20b)%20%3D%20swap(result.0%2C%20result.1)%3B%0A%20%20%20%20println!(%22%7B%7D%20%7B%7D%22%2C%20a%2C%20b)%3B%0A%7D%0A" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals" title="Rust Playground" loading="lazy"></iframe>
                </div>
            </div>
            <!-- <script>
              document.addEventListener("DOMContentLoaded", function() {
                // Select the widget's text element using its XPath
                const xpath = '/html/body/main/div/div/div[1]/div[1]/div/button[1]/div';
                const widgetText = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    
                // Change the text content of the element
                widgetText.textContent = "New Text";
              });
            </script> -->
    
            <script>
            var pres = document.querySelectorAll("pre>code");
            for (var i = 0; i < pres.length; i++) {
                hljs.highlightElement(pres[i]);
            }
            var options = {
                loadDelay: 0,
                copyIconClass: "far fa-clipboard",
                checkIconClass: "fa fa-check text-success",
                blogURL: "http://rust-study.ajousw.kr/"
            };
            window.highlightJsBadge(options);
            </script>
    
            <footer>
              <p>아주대학교 Software Tool Time - Rust 튜토리얼 (Basic)</p>
            </footer>
        </body>
    </html>