Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 4e2dbb669434a7691662cb2f0ad38972 > files > 11276

rust-doc-1.28.0-1.mga6.armv7hl.rpm

<!DOCTYPE HTML>
<html lang="en" class="sidebar-visible no-js">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>Generics - Rust By Example</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="A description">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff" />

        <base href="">

        <link rel="stylesheet" href="book.css">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">

        <link rel="shortcut icon" href="favicon.png">

        <!-- Font Awesome -->
        <link rel="stylesheet" href="_FontAwesome/css/font-awesome.css">

        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->
        

        

    </head>
    <body class="light">
        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script type="text/javascript">
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script type="text/javascript">
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } 
            if (theme === null || theme === undefined) { theme = 'light'; }
            document.body.className = theme;
            document.querySelector('html').className = theme + ' js';
        </script>

        <!-- Hide / unhide sidebar before it is displayed -->
        <script type="text/javascript">
            var html = document.querySelector('html');
            var sidebar = 'hidden';
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            }
            html.classList.remove('sidebar-visible');
            html.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <ol class="chapter"><li class="affix"><a href="index.html">Introduction</a></li><li><a href="hello.html"><strong aria-hidden="true">1.</strong> Hello World</a></li><li><ol class="section"><li><a href="hello/comment.html"><strong aria-hidden="true">1.1.</strong> Comments</a></li><li><a href="hello/print.html"><strong aria-hidden="true">1.2.</strong> Formatted print</a></li><li><ol class="section"><li><a href="hello/print/print_debug.html"><strong aria-hidden="true">1.2.1.</strong> Debug</a></li><li><a href="hello/print/print_display.html"><strong aria-hidden="true">1.2.2.</strong> Display</a></li><li><ol class="section"><li><a href="hello/print/print_display/testcase_list.html"><strong aria-hidden="true">1.2.2.1.</strong> Testcase: List</a></li></ol></li><li><a href="hello/print/fmt.html"><strong aria-hidden="true">1.2.3.</strong> Formatting</a></li></ol></li></ol></li><li><a href="primitives.html"><strong aria-hidden="true">2.</strong> Primitives</a></li><li><ol class="section"><li><a href="primitives/literals.html"><strong aria-hidden="true">2.1.</strong> Literals and operators</a></li><li><a href="primitives/tuples.html"><strong aria-hidden="true">2.2.</strong> Tuples</a></li><li><a href="primitives/array.html"><strong aria-hidden="true">2.3.</strong> Arrays and Slices</a></li></ol></li><li><a href="custom_types.html"><strong aria-hidden="true">3.</strong> Custom Types</a></li><li><ol class="section"><li><a href="custom_types/structs.html"><strong aria-hidden="true">3.1.</strong> Structures</a></li><li><a href="custom_types/enum.html"><strong aria-hidden="true">3.2.</strong> Enums</a></li><li><ol class="section"><li><a href="custom_types/enum/enum_use.html"><strong aria-hidden="true">3.2.1.</strong> use</a></li><li><a href="custom_types/enum/c_like.html"><strong aria-hidden="true">3.2.2.</strong> C-like</a></li><li><a href="custom_types/enum/testcase_linked_list.html"><strong aria-hidden="true">3.2.3.</strong> Testcase: linked-list</a></li></ol></li><li><a href="custom_types/constants.html"><strong aria-hidden="true">3.3.</strong> constants</a></li></ol></li><li><a href="variable_bindings.html"><strong aria-hidden="true">4.</strong> Variable Bindings</a></li><li><ol class="section"><li><a href="variable_bindings/mut.html"><strong aria-hidden="true">4.1.</strong> Mutability</a></li><li><a href="variable_bindings/scope.html"><strong aria-hidden="true">4.2.</strong> Scope and Shadowing</a></li><li><a href="variable_bindings/declare.html"><strong aria-hidden="true">4.3.</strong> Declare first</a></li></ol></li><li><a href="types.html"><strong aria-hidden="true">5.</strong> Types</a></li><li><ol class="section"><li><a href="types/cast.html"><strong aria-hidden="true">5.1.</strong> Casting</a></li><li><a href="types/literals.html"><strong aria-hidden="true">5.2.</strong> Literals</a></li><li><a href="types/inference.html"><strong aria-hidden="true">5.3.</strong> Inference</a></li><li><a href="types/alias.html"><strong aria-hidden="true">5.4.</strong> Aliasing</a></li></ol></li><li><a href="conversion.html"><strong aria-hidden="true">6.</strong> Conversion</a></li><li><ol class="section"><li><a href="conversion/from_into.html"><strong aria-hidden="true">6.1.</strong> From and Into</a></li><li><a href="conversion/string.html"><strong aria-hidden="true">6.2.</strong> To and from Strings</a></li></ol></li><li><a href="expression.html"><strong aria-hidden="true">7.</strong> Expressions</a></li><li><a href="flow_control.html"><strong aria-hidden="true">8.</strong> Flow Control</a></li><li><ol class="section"><li><a href="flow_control/if_else.html"><strong aria-hidden="true">8.1.</strong> if/else</a></li><li><a href="flow_control/loop.html"><strong aria-hidden="true">8.2.</strong> loop</a></li><li><ol class="section"><li><a href="flow_control/loop/nested.html"><strong aria-hidden="true">8.2.1.</strong> Nesting and labels</a></li><li><a href="flow_control/loop/return.html"><strong aria-hidden="true">8.2.2.</strong> Returning from loops</a></li></ol></li><li><a href="flow_control/while.html"><strong aria-hidden="true">8.3.</strong> while</a></li><li><a href="flow_control/for.html"><strong aria-hidden="true">8.4.</strong> for and range</a></li><li><a href="flow_control/match.html"><strong aria-hidden="true">8.5.</strong> match</a></li><li><ol class="section"><li><a href="flow_control/match/destructuring.html"><strong aria-hidden="true">8.5.1.</strong> Destructuring</a></li><li><ol class="section"><li><a href="flow_control/match/destructuring/destructure_tuple.html"><strong aria-hidden="true">8.5.1.1.</strong> tuples</a></li><li><a href="flow_control/match/destructuring/destructure_enum.html"><strong aria-hidden="true">8.5.1.2.</strong> enums</a></li><li><a href="flow_control/match/destructuring/destructure_pointers.html"><strong aria-hidden="true">8.5.1.3.</strong> pointers/ref</a></li><li><a href="flow_control/match/destructuring/destructure_structures.html"><strong aria-hidden="true">8.5.1.4.</strong> structs</a></li></ol></li><li><a href="flow_control/match/guard.html"><strong aria-hidden="true">8.5.2.</strong> Guards</a></li><li><a href="flow_control/match/binding.html"><strong aria-hidden="true">8.5.3.</strong> Binding</a></li></ol></li><li><a href="flow_control/if_let.html"><strong aria-hidden="true">8.6.</strong> if let</a></li><li><a href="flow_control/while_let.html"><strong aria-hidden="true">8.7.</strong> while let</a></li></ol></li><li><a href="fn.html"><strong aria-hidden="true">9.</strong> Functions</a></li><li><ol class="section"><li><a href="fn/methods.html"><strong aria-hidden="true">9.1.</strong> Methods</a></li><li><a href="fn/closures.html"><strong aria-hidden="true">9.2.</strong> Closures</a></li><li><ol class="section"><li><a href="fn/closures/capture.html"><strong aria-hidden="true">9.2.1.</strong> Capturing</a></li><li><a href="fn/closures/input_parameters.html"><strong aria-hidden="true">9.2.2.</strong> As input parameters</a></li><li><a href="fn/closures/anonymity.html"><strong aria-hidden="true">9.2.3.</strong> Type anonymity</a></li><li><a href="fn/closures/input_functions.html"><strong aria-hidden="true">9.2.4.</strong> Input functions</a></li><li><a href="fn/closures/output_parameters.html"><strong aria-hidden="true">9.2.5.</strong> As output parameters</a></li><li><a href="fn/closures/closure_examples.html"><strong aria-hidden="true">9.2.6.</strong> Examples in std</a></li><li><ol class="section"><li><a href="fn/closures/closure_examples/iter_any.html"><strong aria-hidden="true">9.2.6.1.</strong> Iterator::any</a></li><li><a href="fn/closures/closure_examples/iter_find.html"><strong aria-hidden="true">9.2.6.2.</strong> Iterator::find</a></li></ol></li></ol></li><li><a href="fn/hof.html"><strong aria-hidden="true">9.3.</strong> Higher Order Functions</a></li><li><a href="fn/diverging.html"><strong aria-hidden="true">9.4.</strong> Diverging functions</a></li></ol></li><li><a href="mod.html"><strong aria-hidden="true">10.</strong> Modules</a></li><li><ol class="section"><li><a href="mod/visibility.html"><strong aria-hidden="true">10.1.</strong> Visibility</a></li><li><a href="mod/struct_visibility.html"><strong aria-hidden="true">10.2.</strong> Struct visibility</a></li><li><a href="mod/use.html"><strong aria-hidden="true">10.3.</strong> The use declaration</a></li><li><a href="mod/super.html"><strong aria-hidden="true">10.4.</strong> super and self</a></li><li><a href="mod/split.html"><strong aria-hidden="true">10.5.</strong> File hierarchy</a></li></ol></li><li><a href="crates.html"><strong aria-hidden="true">11.</strong> Crates</a></li><li><ol class="section"><li><a href="crates/lib.html"><strong aria-hidden="true">11.1.</strong> Library</a></li><li><a href="crates/link.html"><strong aria-hidden="true">11.2.</strong> extern crate</a></li></ol></li><li><a href="cargo.html"><strong aria-hidden="true">12.</strong> Cargo</a></li><li><ol class="section"><li><a href="cargo/deps.html"><strong aria-hidden="true">12.1.</strong> Dependencies</a></li><li><a href="cargo/conventions.html"><strong aria-hidden="true">12.2.</strong> Conventions</a></li><li><a href="cargo/test.html"><strong aria-hidden="true">12.3.</strong> Tests</a></li></ol></li><li><a href="attribute.html"><strong aria-hidden="true">13.</strong> Attributes</a></li><li><ol class="section"><li><a href="attribute/unused.html"><strong aria-hidden="true">13.1.</strong> dead_code</a></li><li><a href="attribute/crate.html"><strong aria-hidden="true">13.2.</strong> Crates</a></li><li><a href="attribute/cfg.html"><strong aria-hidden="true">13.3.</strong> cfg</a></li><li><ol class="section"><li><a href="attribute/cfg/custom.html"><strong aria-hidden="true">13.3.1.</strong> Custom</a></li></ol></li></ol></li><li><a href="generics.html" class="active"><strong aria-hidden="true">14.</strong> Generics</a></li><li><ol class="section"><li><a href="generics/gen_fn.html"><strong aria-hidden="true">14.1.</strong> Functions</a></li><li><a href="generics/impl.html"><strong aria-hidden="true">14.2.</strong> Implementation</a></li><li><a href="generics/gen_trait.html"><strong aria-hidden="true">14.3.</strong> Traits</a></li><li><a href="generics/bounds.html"><strong aria-hidden="true">14.4.</strong> Bounds</a></li><li><ol class="section"><li><a href="generics/bounds/testcase_empty.html"><strong aria-hidden="true">14.4.1.</strong> Testcase: empty bounds</a></li></ol></li><li><a href="generics/multi_bounds.html"><strong aria-hidden="true">14.5.</strong> Multiple bounds</a></li><li><a href="generics/where.html"><strong aria-hidden="true">14.6.</strong> Where clauses</a></li><li><a href="generics/new_types.html"><strong aria-hidden="true">14.7.</strong> New Type Idiom</a></li><li><a href="generics/assoc_items.html"><strong aria-hidden="true">14.8.</strong> Associated items</a></li><li><ol class="section"><li><a href="generics/assoc_items/the_problem.html"><strong aria-hidden="true">14.8.1.</strong> The Problem</a></li><li><a href="generics/assoc_items/types.html"><strong aria-hidden="true">14.8.2.</strong> Associated types</a></li></ol></li><li><a href="generics/phantom.html"><strong aria-hidden="true">14.9.</strong> Phantom type parameters</a></li><li><ol class="section"><li><a href="generics/phantom/testcase_units.html"><strong aria-hidden="true">14.9.1.</strong> Testcase: unit clarification</a></li></ol></li></ol></li><li><a href="scope.html"><strong aria-hidden="true">15.</strong> Scoping rules</a></li><li><ol class="section"><li><a href="scope/raii.html"><strong aria-hidden="true">15.1.</strong> RAII</a></li><li><a href="scope/move.html"><strong aria-hidden="true">15.2.</strong> Ownership and moves</a></li><li><ol class="section"><li><a href="scope/move/mut.html"><strong aria-hidden="true">15.2.1.</strong> Mutability</a></li></ol></li><li><a href="scope/borrow.html"><strong aria-hidden="true">15.3.</strong> Borrowing</a></li><li><ol class="section"><li><a href="scope/borrow/mut.html"><strong aria-hidden="true">15.3.1.</strong> Mutability</a></li><li><a href="scope/borrow/freeze.html"><strong aria-hidden="true">15.3.2.</strong> Freezing</a></li><li><a href="scope/borrow/alias.html"><strong aria-hidden="true">15.3.3.</strong> Aliasing</a></li><li><a href="scope/borrow/ref.html"><strong aria-hidden="true">15.3.4.</strong> The ref pattern</a></li></ol></li><li><a href="scope/lifetime.html"><strong aria-hidden="true">15.4.</strong> Lifetimes</a></li><li><ol class="section"><li><a href="scope/lifetime/explicit.html"><strong aria-hidden="true">15.4.1.</strong> Explicit annotation</a></li><li><a href="scope/lifetime/fn.html"><strong aria-hidden="true">15.4.2.</strong> Functions</a></li><li><a href="scope/lifetime/methods.html"><strong aria-hidden="true">15.4.3.</strong> Methods</a></li><li><a href="scope/lifetime/struct.html"><strong aria-hidden="true">15.4.4.</strong> Structs</a></li><li><a href="scope/lifetime/lifetime_bounds.html"><strong aria-hidden="true">15.4.5.</strong> Bounds</a></li><li><a href="scope/lifetime/lifetime_coercion.html"><strong aria-hidden="true">15.4.6.</strong> Coercion</a></li><li><a href="scope/lifetime/static_lifetime.html"><strong aria-hidden="true">15.4.7.</strong> Static</a></li><li><a href="scope/lifetime/elision.html"><strong aria-hidden="true">15.4.8.</strong> Elision</a></li></ol></li></ol></li><li><a href="trait.html"><strong aria-hidden="true">16.</strong> Traits</a></li><li><ol class="section"><li><a href="trait/derive.html"><strong aria-hidden="true">16.1.</strong> Derive</a></li><li><a href="trait/ops.html"><strong aria-hidden="true">16.2.</strong> Operator Overloading</a></li><li><a href="trait/drop.html"><strong aria-hidden="true">16.3.</strong> Drop</a></li><li><a href="trait/iter.html"><strong aria-hidden="true">16.4.</strong> Iterators</a></li><li><a href="trait/clone.html"><strong aria-hidden="true">16.5.</strong> Clone</a></li></ol></li><li><a href="macros.html"><strong aria-hidden="true">17.</strong> macro_rules!</a></li><li><ol class="section"><li><a href="macros/syntax.html"><strong aria-hidden="true">17.1.</strong> Syntax</a></li><li><ol class="section"><li><a href="macros/designators.html"><strong aria-hidden="true">17.1.1.</strong> Designators</a></li><li><a href="macros/overload.html"><strong aria-hidden="true">17.1.2.</strong> Overload</a></li><li><a href="macros/repeat.html"><strong aria-hidden="true">17.1.3.</strong> Repeat</a></li></ol></li><li><a href="macros/dry.html"><strong aria-hidden="true">17.2.</strong> DRY (Don't Repeat Yourself)</a></li><li><a href="macros/dsl.html"><strong aria-hidden="true">17.3.</strong> DSL (Domain Specific Languages)</a></li><li><a href="macros/variadics.html"><strong aria-hidden="true">17.4.</strong> Variadics</a></li></ol></li><li><a href="error.html"><strong aria-hidden="true">18.</strong> Error handling</a></li><li><ol class="section"><li><a href="error/panic.html"><strong aria-hidden="true">18.1.</strong> panic</a></li><li><a href="error/option_unwrap.html"><strong aria-hidden="true">18.2.</strong> Option &amp; unwrap</a></li><li><ol class="section"><li><a href="error/option_unwrap/map.html"><strong aria-hidden="true">18.2.1.</strong> Combinators: map</a></li><li><a href="error/option_unwrap/and_then.html"><strong aria-hidden="true">18.2.2.</strong> Combinators: and_then</a></li></ol></li><li><a href="error/result.html"><strong aria-hidden="true">18.3.</strong> Result</a></li><li><ol class="section"><li><a href="error/result/result_map.html"><strong aria-hidden="true">18.3.1.</strong> map for Result</a></li><li><a href="error/result/result_alias.html"><strong aria-hidden="true">18.3.2.</strong> aliases for Result</a></li><li><a href="error/result/early_returns.html"><strong aria-hidden="true">18.3.3.</strong> Early returns</a></li><li><a href="error/result/enter_question_mark.html"><strong aria-hidden="true">18.3.4.</strong> Introducing ?</a></li></ol></li><li><a href="error/multiple_error_types.html"><strong aria-hidden="true">18.4.</strong> Multiple error types</a></li><li><ol class="section"><li><a href="error/multiple_error_types/option_result.html"><strong aria-hidden="true">18.4.1.</strong> Pulling Results out of Options</a></li><li><a href="error/multiple_error_types/define_error_type.html"><strong aria-hidden="true">18.4.2.</strong> Defining an error type</a></li><li><a href="error/multiple_error_types/boxing_errors.html"><strong aria-hidden="true">18.4.3.</strong> Boxing errors</a></li><li><a href="error/multiple_error_types/reenter_question_mark.html"><strong aria-hidden="true">18.4.4.</strong> Other uses of ?</a></li><li><a href="error/multiple_error_types/wrap_error.html"><strong aria-hidden="true">18.4.5.</strong> Wrapping errors</a></li></ol></li><li><a href="error/iter_result.html"><strong aria-hidden="true">18.5.</strong> Iterating over Results</a></li></ol></li><li><a href="std.html"><strong aria-hidden="true">19.</strong> Std library types</a></li><li><ol class="section"><li><a href="std/box.html"><strong aria-hidden="true">19.1.</strong> Box, stack and heap</a></li><li><a href="std/vec.html"><strong aria-hidden="true">19.2.</strong> Vectors</a></li><li><a href="std/str.html"><strong aria-hidden="true">19.3.</strong> Strings</a></li><li><a href="std/option.html"><strong aria-hidden="true">19.4.</strong> Option</a></li><li><a href="std/result.html"><strong aria-hidden="true">19.5.</strong> Result</a></li><li><ol class="section"><li><a href="std/result/question_mark.html"><strong aria-hidden="true">19.5.1.</strong> ?</a></li></ol></li><li><a href="std/panic.html"><strong aria-hidden="true">19.6.</strong> panic!</a></li><li><a href="std/hash.html"><strong aria-hidden="true">19.7.</strong> HashMap</a></li><li><ol class="section"><li><a href="std/hash/alt_key_types.html"><strong aria-hidden="true">19.7.1.</strong> Alternate/custom key types</a></li><li><a href="std/hash/hashset.html"><strong aria-hidden="true">19.7.2.</strong> HashSet</a></li></ol></li></ol></li><li><a href="std_misc.html"><strong aria-hidden="true">20.</strong> Std misc</a></li><li><ol class="section"><li><a href="std_misc/threads.html"><strong aria-hidden="true">20.1.</strong> Threads</a></li><li><ol class="section"><li><a href="std_misc/threads/testcase_mapreduce.html"><strong aria-hidden="true">20.1.1.</strong> Testcase: map-reduce</a></li></ol></li><li><a href="std_misc/channels.html"><strong aria-hidden="true">20.2.</strong> Channels</a></li><li><a href="std_misc/path.html"><strong aria-hidden="true">20.3.</strong> Path</a></li><li><a href="std_misc/file.html"><strong aria-hidden="true">20.4.</strong> File I/O</a></li><li><ol class="section"><li><a href="std_misc/file/open.html"><strong aria-hidden="true">20.4.1.</strong> open</a></li><li><a href="std_misc/file/create.html"><strong aria-hidden="true">20.4.2.</strong> create</a></li></ol></li><li><a href="std_misc/process.html"><strong aria-hidden="true">20.5.</strong> Child processes</a></li><li><ol class="section"><li><a href="std_misc/process/pipe.html"><strong aria-hidden="true">20.5.1.</strong> Pipes</a></li><li><a href="std_misc/process/wait.html"><strong aria-hidden="true">20.5.2.</strong> Wait</a></li></ol></li><li><a href="std_misc/fs.html"><strong aria-hidden="true">20.6.</strong> Filesystem Operations</a></li><li><a href="std_misc/arg.html"><strong aria-hidden="true">20.7.</strong> Program arguments</a></li><li><ol class="section"><li><a href="std_misc/arg/matching.html"><strong aria-hidden="true">20.7.1.</strong> Argument parsing</a></li></ol></li><li><a href="std_misc/ffi.html"><strong aria-hidden="true">20.8.</strong> Foreign Function Interface</a></li></ol></li><li><a href="testing.html"><strong aria-hidden="true">21.</strong> Testing</a></li><li><ol class="section"><li><a href="testing/unit_testing.html"><strong aria-hidden="true">21.1.</strong> Unit testing</a></li><li><a href="testing/doc_testing.html"><strong aria-hidden="true">21.2.</strong> Documentation testing</a></li><li><a href="testing/integration_testing.html"><strong aria-hidden="true">21.3.</strong> Integration testing</a></li><li><a href="testing/dev_dependencies.html"><strong aria-hidden="true">21.4.</strong> Dev-dependencies</a></li></ol></li><li><a href="meta.html"><strong aria-hidden="true">22.</strong> Meta</a></li><li><ol class="section"><li><a href="meta/doc.html"><strong aria-hidden="true">22.1.</strong> Documentation</a></li></ol></li><li><a href="unsafe.html"><strong aria-hidden="true">23.</strong> Unsafe Operations</a></li></ol>
        </nav>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                
                <div id="menu-bar" class="menu-bar">
                    <div id="menu-bar-sticky-container">
                        <div class="left-buttons">
                            <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                                <i class="fa fa-bars"></i>
                            </button>
                            <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                                <i class="fa fa-paint-brush"></i>
                            </button>
                            <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                                <li role="none"><button role="menuitem" class="theme" id="light">Light <span class="default">(default)</span></button></li>
                                <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                                <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                            </ul>
                            
                            <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                                <i class="fa fa-search"></i>
                            </button>
                            
                        </div>

                        <h1 class="menu-title">Rust By Example</h1> 

                        <div class="right-buttons">
                            <a href="print.html" title="Print this book" aria-label="Print this book">
                                <i id="print-button" class="fa fa-print"></i>
                            </a>
                        </div>
                    </div>
                </div>

                
                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" name="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>
                

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script type="text/javascript">
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <a class="header" href="generics.html#generics" id="generics"><h1>Generics</h1></a>
<p><em>Generics</em> is the topic of generalizing types and functionalities to broader
cases. This is extremely useful for reducing code duplication in many ways,
but can call for rather involving syntax. Namely, being generic requires
taking great care to specify over which types a generic type
is actually considered valid. The simplest and most common use of generics
is for type parameters.</p>
<p>A type parameter is specified as generic by the use of angle brackets and upper
<a href="https://en.wikipedia.org/wiki/CamelCase">camel case</a>: <code>&lt;Aaa, Bbb, ...&gt;</code>. &quot;Generic type parameters&quot; are
typically represented as <code>&lt;T&gt;</code>. In Rust, &quot;generic&quot; also describes anything that
accepts one or more generic type parameters <code>&lt;T&gt;</code>. Any type specified as a
generic type parameter is generic, and everything else is concrete (non-generic).</p>
<p>For example, defining a <em>generic function</em> named <code>foo</code> that takes an argument
<code>T</code> of any type:</p>
<pre><code class="language-rust ignore">fn foo&lt;T&gt;(arg: T) { ... }
</code></pre>
<p>Because <code>T</code> has been specified as a generic type parameter using <code>&lt;T&gt;</code>, it
is considered generic when used here as <code>(arg: T)</code>. This is the case even if <code>T</code>
has previously been defined as a <code>struct</code>.</p>
<p>This example shows some of the syntax in action:</p>
<pre><pre class="playpen"><code class="language-rust editable">// A concrete type `A`.
struct A;

// In defining the type `Single`, the first use of `A` is not preceded by `&lt;A&gt;`.
// Therefore, `Single` is a concrete type, and `A` is defined as above.
struct Single(A);
//            ^ Here is `Single`s first use of the type `A`.

// Here, `&lt;T&gt;` precedes the first use of `T`, so `SingleGen` is a generic type.
// Because the type parameter `T` is generic, it could be anything, including
// the concrete type `A` defined at the top.
struct SingleGen&lt;T&gt;(T);

fn main() {
    // `Single` is concrete and explicitly takes `A`.
    let _s = Single(A);
    
    // Create a variable `_char` of type `SingleGen&lt;char&gt;`
    // and give it the value `SingleGen('a')`.
    // Here, `SingleGen` has a type parameter explicitly specified.
    let _char: SingleGen&lt;char&gt; = SingleGen('a');

    // `SingleGen` can also have a type parameter implicitly specified:
    let _t    = SingleGen(A); // Uses `A` defined at the top.
    let _i32  = SingleGen(6); // Uses `i32`.
    let _char = SingleGen('a'); // Uses `char`.
}
</code></pre></pre>
<a class="header" href="generics.html#see-also" id="see-also"><h3>See also:</h3></a>
<p><a href="custom_types/structs.html"><code>struct</code>s</a></p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                        
                            <a rel="prev" href="attribute/cfg/custom.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        

                        
                            <a rel="next" href="generics/gen_fn.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>
                        

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                
                    <a href="attribute/cfg/custom.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>
                

                
                    <a href="generics/gen_fn.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
                
            </nav>

        </div>

        

        

        

        
        <script src="ace.js" type="text/javascript" charset="utf-8"></script>
        <script src="editor.js" type="text/javascript" charset="utf-8"></script>
        <script src="mode-rust.js" type="text/javascript" charset="utf-8"></script>
        <script src="theme-dawn.js" type="text/javascript" charset="utf-8"></script>
        <script src="theme-tomorrow_night.js" type="text/javascript" charset="utf-8"></script>
        

        
        <script src="searchindex.js" type="text/javascript" charset="utf-8"></script>
        
        
        <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
        

        <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
        <script src="book.js" type="text/javascript" charset="utf-8"></script>

        <!-- Custom JS scripts -->
        

    </body>
</html>