616 lines
44 KiB
HTML
616 lines
44 KiB
HTML
<!DOCTYPE HTML>
|
||
<html lang="en" class="light sidebar-visible" dir="ltr">
|
||
<head>
|
||
<!-- Book generated using mdBook -->
|
||
<meta charset="UTF-8">
|
||
<title>Data Types - The Rust Programming Language</title>
|
||
|
||
|
||
<!-- Custom HTML head -->
|
||
|
||
<meta name="description" content="">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<meta name="theme-color" content="#ffffff">
|
||
|
||
<link rel="icon" href="favicon-de23e50b.svg">
|
||
<link rel="shortcut icon" href="favicon-8114d1fc.png">
|
||
<link rel="stylesheet" href="css/variables-8adf115d.css">
|
||
<link rel="stylesheet" href="css/general-0392ca55.css">
|
||
<link rel="stylesheet" href="css/chrome-fc474251.css">
|
||
<link rel="stylesheet" href="css/print-9e4910d8.css" media="print">
|
||
|
||
<!-- Fonts -->
|
||
<link rel="stylesheet" href="fonts/fonts-9644e21d.css">
|
||
|
||
<!-- Highlight.js Stylesheets -->
|
||
<link rel="stylesheet" id="mdbook-highlight-css" href="highlight-493f70e1.css">
|
||
<link rel="stylesheet" id="mdbook-tomorrow-night-css" href="tomorrow-night-4c0ae647.css">
|
||
<link rel="stylesheet" id="mdbook-ayu-highlight-css" href="ayu-highlight-3fdfc3ac.css">
|
||
|
||
<!-- Custom theme stylesheets -->
|
||
<link rel="stylesheet" href="ferris-d33b75bf.css">
|
||
<link rel="stylesheet" href="theme/2018-edition-4e126c62.css">
|
||
<link rel="stylesheet" href="theme/semantic-notes-9b5766c0.css">
|
||
<link rel="stylesheet" href="theme/listing-cab26221.css">
|
||
|
||
|
||
<!-- Provide site root and default themes to javascript -->
|
||
<script>
|
||
const path_to_root = "";
|
||
const default_light_theme = "light";
|
||
const default_dark_theme = "navy";
|
||
window.path_to_searchindex_js = "searchindex-6a1da8cc.js";
|
||
</script>
|
||
<!-- Start loading toc.js asap -->
|
||
<script src="toc-0e4ce700.js"></script>
|
||
</head>
|
||
<body>
|
||
<div id="mdbook-help-container">
|
||
<div id="mdbook-help-popup">
|
||
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
|
||
<div>
|
||
<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>
|
||
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
|
||
<p>Press <kbd>?</kbd> to show this help</p>
|
||
<p>Press <kbd>Esc</kbd> to hide this help</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="mdbook-body-container">
|
||
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
||
<script>
|
||
try {
|
||
let theme = localStorage.getItem('mdbook-theme');
|
||
let 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>
|
||
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
|
||
let theme;
|
||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||
if (theme === null || theme === undefined) { theme = default_theme; }
|
||
const html = document.documentElement;
|
||
html.classList.remove('light')
|
||
html.classList.add(theme);
|
||
html.classList.add("js");
|
||
</script>
|
||
|
||
<input type="checkbox" id="mdbook-sidebar-toggle-anchor" class="hidden">
|
||
|
||
<!-- Hide / unhide sidebar before it is displayed -->
|
||
<script>
|
||
let sidebar = null;
|
||
const sidebar_toggle = document.getElementById("mdbook-sidebar-toggle-anchor");
|
||
if (document.body.clientWidth >= 1080) {
|
||
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
||
sidebar = sidebar || 'visible';
|
||
} else {
|
||
sidebar = 'hidden';
|
||
sidebar_toggle.checked = false;
|
||
}
|
||
if (sidebar === 'visible') {
|
||
sidebar_toggle.checked = true;
|
||
} else {
|
||
html.classList.remove('sidebar-visible');
|
||
}
|
||
</script>
|
||
|
||
<nav id="mdbook-sidebar" class="sidebar" aria-label="Table of contents">
|
||
<!-- populated by js -->
|
||
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
|
||
<noscript>
|
||
<iframe class="sidebar-iframe-outer" src="toc.html"></iframe>
|
||
</noscript>
|
||
<div id="mdbook-sidebar-resize-handle" class="sidebar-resize-handle">
|
||
<div class="sidebar-resize-indicator"></div>
|
||
</div>
|
||
</nav>
|
||
|
||
<div id="mdbook-page-wrapper" class="page-wrapper">
|
||
|
||
<div class="page">
|
||
<div id="mdbook-menu-bar-hover-placeholder"></div>
|
||
<div id="mdbook-menu-bar" class="menu-bar sticky">
|
||
<div class="left-buttons">
|
||
<label id="mdbook-sidebar-toggle" class="icon-button" for="mdbook-sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="mdbook-sidebar">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M0 96C0 78.3 14.3 64 32 64H416c17.7 0 32 14.3 32 32s-14.3 32-32 32H32C14.3 128 0 113.7 0 96zM0 256c0-17.7 14.3-32 32-32H416c17.7 0 32 14.3 32 32s-14.3 32-32 32H32c-17.7 0-32-14.3-32-32zM448 416c0 17.7-14.3 32-32 32H32c-17.7 0-32-14.3-32-32s14.3-32 32-32H416c17.7 0 32 14.3 32 32z"/></svg></span>
|
||
</label>
|
||
<button id="mdbook-theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="mdbook-theme-list">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M371.3 367.1c27.3-3.9 51.9-19.4 67.2-42.9L600.2 74.1c12.6-19.5 9.4-45.3-7.6-61.2S549.7-4.4 531.1 9.6L294.4 187.2c-24 18-38.2 46.1-38.4 76.1L371.3 367.1zm-19.6 25.4l-116-104.4C175.9 290.3 128 339.6 128 400c0 3.9 .2 7.8 .6 11.6c1.8 17.5-10.2 36.4-27.8 36.4H96c-17.7 0-32 14.3-32 32s14.3 32 32 32H240c61.9 0 112-50.1 112-112c0-2.5-.1-5-.2-7.5z"/></svg></span>
|
||
</button>
|
||
<ul id="mdbook-theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
||
<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-default_theme">Auto</button></li>
|
||
<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-light">Light</button></li>
|
||
<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-rust">Rust</button></li>
|
||
<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-coal">Coal</button></li>
|
||
<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-navy">Navy</button></li>
|
||
<li role="none"><button role="menuitem" class="theme" id="mdbook-theme-ayu">Ayu</button></li>
|
||
</ul>
|
||
<button id="mdbook-search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="mdbook-searchbar">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352c79.5 0 144-64.5 144-144s-64.5-144-144-144S64 128.5 64 208s64.5 144 144 144z"/></svg></span>
|
||
</button>
|
||
</div>
|
||
|
||
<h1 class="menu-title">The Rust Programming Language</h1>
|
||
|
||
<div class="right-buttons">
|
||
<a href="print.html" title="Print this book" aria-label="Print this book">
|
||
<span class=fa-svg id="print-button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M128 0C92.7 0 64 28.7 64 64v96h64V64H354.7L384 93.3V160h64V93.3c0-17-6.7-33.3-18.7-45.3L400 18.7C388 6.7 371.7 0 354.7 0H128zM384 352v32 64H128V384 368 352H384zm64 32h32c17.7 0 32-14.3 32-32V256c0-35.3-28.7-64-64-64H64c-35.3 0-64 28.7-64 64v96c0 17.7 14.3 32 32 32H64v64c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V384zm-16-88c-13.3 0-24-10.7-24-24s10.7-24 24-24s24 10.7 24 24s-10.7 24-24 24z"/></svg></span>
|
||
</a>
|
||
<a href="https://github.com/rust-lang/book" title="Git repository" aria-label="Git repository">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg></span>
|
||
</a>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<div id="mdbook-search-wrapper" class="hidden">
|
||
<form id="mdbook-searchbar-outer" class="searchbar-outer">
|
||
<div class="search-wrapper">
|
||
<input type="search" id="mdbook-searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="mdbook-searchresults-outer" aria-describedby="searchresults-header">
|
||
<div class="spinner-wrapper">
|
||
<span class=fa-svg id="fa-spin"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M304 48c0-26.5-21.5-48-48-48s-48 21.5-48 48s21.5 48 48 48s48-21.5 48-48zm0 416c0-26.5-21.5-48-48-48s-48 21.5-48 48s21.5 48 48 48s48-21.5 48-48zM48 304c26.5 0 48-21.5 48-48s-21.5-48-48-48s-48 21.5-48 48s21.5 48 48 48zm464-48c0-26.5-21.5-48-48-48s-48 21.5-48 48s21.5 48 48 48s48-21.5 48-48zM142.9 437c18.7-18.7 18.7-49.1 0-67.9s-49.1-18.7-67.9 0s-18.7 49.1 0 67.9s49.1 18.7 67.9 0zm0-294.2c18.7-18.7 18.7-49.1 0-67.9S93.7 56.2 75 75s-18.7 49.1 0 67.9s49.1 18.7 67.9 0zM369.1 437c18.7 18.7 49.1 18.7 67.9 0s18.7-49.1 0-67.9s-49.1-18.7-67.9 0s-18.7 49.1 0 67.9z"/></svg></span>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
<div id="mdbook-searchresults-outer" class="searchresults-outer hidden">
|
||
<div id="mdbook-searchresults-header" class="searchresults-header"></div>
|
||
<ul id="mdbook-searchresults">
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
||
<script>
|
||
document.getElementById('mdbook-sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
||
document.getElementById('mdbook-sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
||
Array.from(document.querySelectorAll('#mdbook-sidebar a')).forEach(function(link) {
|
||
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
||
});
|
||
</script>
|
||
|
||
<div id="mdbook-content" class="content">
|
||
<main>
|
||
<h2 id="data-types"><a class="header" href="#data-types">Data Types</a></h2>
|
||
<p>Every value in Rust is of a certain <em>data type</em>, which tells Rust what kind of
|
||
data is being specified so that it knows how to work with that data. We’ll look
|
||
at two data type subsets: scalar and compound.</p>
|
||
<p>Keep in mind that Rust is a <em>statically typed</em> language, which means that it
|
||
must know the types of all variables at compile time. The compiler can usually
|
||
infer what type we want to use based on the value and how we use it. In cases
|
||
when many types are possible, such as when we converted a <code>String</code> to a numeric
|
||
type using <code>parse</code> in the <a href="ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number">“Comparing the Guess to the Secret
|
||
Number”</a><!-- ignore --> section in
|
||
Chapter 2, we must add a type annotation, like this:</p>
|
||
<pre class="playground"><code class="language-rust edition2024"><span class="boring">#![allow(unused)]
|
||
</span><span class="boring">fn main() {
|
||
</span>let guess: u32 = "42".parse().expect("Not a number!");
|
||
<span class="boring">}</span></code></pre>
|
||
<p>If we don’t add the <code>: u32</code> type annotation shown in the preceding code, Rust
|
||
will display the following error, which means the compiler needs more
|
||
information from us to know which type we want to use:</p>
|
||
<pre><code class="language-console">$ cargo build
|
||
Compiling no_type_annotations v0.1.0 (file:///projects/no_type_annotations)
|
||
error[E0284]: type annotations needed
|
||
--> src/main.rs:2:9
|
||
|
|
||
2 | let guess = "42".parse().expect("Not a number!");
|
||
| ^^^^^ ----- type must be known at this point
|
||
|
|
||
= note: cannot satisfy `<_ as FromStr>::Err == _`
|
||
help: consider giving `guess` an explicit type
|
||
|
|
||
2 | let guess: /* Type */ = "42".parse().expect("Not a number!");
|
||
| ++++++++++++
|
||
|
||
For more information about this error, try `rustc --explain E0284`.
|
||
error: could not compile `no_type_annotations` (bin "no_type_annotations") due to 1 previous error
|
||
</code></pre>
|
||
<p>You’ll see different type annotations for other data types.</p>
|
||
<h3 id="scalar-types"><a class="header" href="#scalar-types">Scalar Types</a></h3>
|
||
<p>A <em>scalar</em> type represents a single value. Rust has four primary scalar types:
|
||
integers, floating-point numbers, Booleans, and characters. You may recognize
|
||
these from other programming languages. Let’s jump into how they work in Rust.</p>
|
||
<h4 id="integer-types"><a class="header" href="#integer-types">Integer Types</a></h4>
|
||
<p>An <em>integer</em> is a number without a fractional component. We used one integer
|
||
type in Chapter 2, the <code>u32</code> type. This type declaration indicates that the
|
||
value it’s associated with should be an unsigned integer (signed integer types
|
||
start with <code>i</code> instead of <code>u</code>) that takes up 32 bits of space. Table 3-1 shows
|
||
the built-in integer types in Rust. We can use any of these variants to declare
|
||
the type of an integer value.</p>
|
||
<p><span class="caption">Table 3-1: Integer Types in Rust</span></p>
|
||
<div class="table-wrapper">
|
||
<table>
|
||
<thead>
|
||
<tr><th>Length</th><th>Signed</th><th>Unsigned</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>8-bit</td><td><code>i8</code></td><td><code>u8</code></td></tr>
|
||
<tr><td>16-bit</td><td><code>i16</code></td><td><code>u16</code></td></tr>
|
||
<tr><td>32-bit</td><td><code>i32</code></td><td><code>u32</code></td></tr>
|
||
<tr><td>64-bit</td><td><code>i64</code></td><td><code>u64</code></td></tr>
|
||
<tr><td>128-bit</td><td><code>i128</code></td><td><code>u128</code></td></tr>
|
||
<tr><td>Architecture-dependent</td><td><code>isize</code></td><td><code>usize</code></td></tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>Each variant can be either signed or unsigned and has an explicit size.
|
||
<em>Signed</em> and <em>unsigned</em> refer to whether it’s possible for the number to be
|
||
negative—in other words, whether the number needs to have a sign with it
|
||
(signed) or whether it will only ever be positive and can therefore be
|
||
represented without a sign (unsigned). It’s like writing numbers on paper: When
|
||
the sign matters, a number is shown with a plus sign or a minus sign; however,
|
||
when it’s safe to assume the number is positive, it’s shown with no sign.
|
||
Signed numbers are stored using <a href="https://en.wikipedia.org/wiki/Two%27s_complement">two’s complement</a><!-- ignore
|
||
--> representation.</p>
|
||
<p>Each signed variant can store numbers from −(2<sup>n − 1</sup>) to 2<sup>n −
|
||
1</sup> − 1 inclusive, where <em>n</em> is the number of bits that variant uses. So, an
|
||
<code>i8</code> can store numbers from −(2<sup>7</sup>) to 2<sup>7</sup> − 1, which equals
|
||
−128 to 127. Unsigned variants can store numbers from 0 to 2<sup>n</sup> − 1,
|
||
so a <code>u8</code> can store numbers from 0 to 2<sup>8</sup> − 1, which equals 0 to 255.</p>
|
||
<p>Additionally, the <code>isize</code> and <code>usize</code> types depend on the architecture of the
|
||
computer your program is running on: 64 bits if you’re on a 64-bit architecture
|
||
and 32 bits if you’re on a 32-bit architecture.</p>
|
||
<p>You can write integer literals in any of the forms shown in Table 3-2. Note
|
||
that number literals that can be multiple numeric types allow a type suffix,
|
||
such as <code>57u8</code>, to designate the type. Number literals can also use <code>_</code> as a
|
||
visual separator to make the number easier to read, such as <code>1_000</code>, which will
|
||
have the same value as if you had specified <code>1000</code>.</p>
|
||
<p><span class="caption">Table 3-2: Integer Literals in Rust</span></p>
|
||
<div class="table-wrapper">
|
||
<table>
|
||
<thead>
|
||
<tr><th>Number literals</th><th>Example</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>Decimal</td><td><code>98_222</code></td></tr>
|
||
<tr><td>Hex</td><td><code>0xff</code></td></tr>
|
||
<tr><td>Octal</td><td><code>0o77</code></td></tr>
|
||
<tr><td>Binary</td><td><code>0b1111_0000</code></td></tr>
|
||
<tr><td>Byte (<code>u8</code> only)</td><td><code>b'A'</code></td></tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p>So how do you know which type of integer to use? If you’re unsure, Rust’s
|
||
defaults are generally good places to start: Integer types default to <code>i32</code>.
|
||
The primary situation in which you’d use <code>isize</code> or <code>usize</code> is when indexing
|
||
some sort of collection.</p>
|
||
<section class="note" aria-role="note">
|
||
<h5 id="integer-overflow"><a class="header" href="#integer-overflow">Integer Overflow</a></h5>
|
||
<p>Let’s say you have a variable of type <code>u8</code> that can hold values between 0 and
|
||
255. If you try to change the variable to a value outside that range, such as
|
||
256, <em>integer overflow</em> will occur, which can result in one of two behaviors.
|
||
When you’re compiling in debug mode, Rust includes checks for integer overflow
|
||
that cause your program to <em>panic</em> at runtime if this behavior occurs. Rust
|
||
uses the term <em>panicking</em> when a program exits with an error; we’ll discuss
|
||
panics in more depth in the <a href="ch09-01-unrecoverable-errors-with-panic.html">“Unrecoverable Errors with
|
||
<code>panic!</code>”</a><!-- ignore --> section in Chapter
|
||
9.</p>
|
||
<p>When you’re compiling in release mode with the <code>--release</code> flag, Rust does
|
||
<em>not</em> include checks for integer overflow that cause panics. Instead, if
|
||
overflow occurs, Rust performs <em>two’s complement wrapping</em>. In short, values
|
||
greater than the maximum value the type can hold “wrap around” to the minimum
|
||
of the values the type can hold. In the case of a <code>u8</code>, the value 256 becomes
|
||
0, the value 257 becomes 1, and so on. The program won’t panic, but the
|
||
variable will have a value that probably isn’t what you were expecting it to
|
||
have. Relying on integer overflow’s wrapping behavior is considered an error.</p>
|
||
<p>To explicitly handle the possibility of overflow, you can use these families
|
||
of methods provided by the standard library for primitive numeric types:</p>
|
||
<ul>
|
||
<li>Wrap in all modes with the <code>wrapping_*</code> methods, such as <code>wrapping_add</code>.</li>
|
||
<li>Return the <code>None</code> value if there is overflow with the <code>checked_*</code> methods.</li>
|
||
<li>Return the value and a Boolean indicating whether there was overflow with
|
||
the <code>overflowing_*</code> methods.</li>
|
||
<li>Saturate at the value’s minimum or maximum values with the <code>saturating_*</code>
|
||
methods.</li>
|
||
</ul>
|
||
</section>
|
||
<h4 id="floating-point-types"><a class="header" href="#floating-point-types">Floating-Point Types</a></h4>
|
||
<p>Rust also has two primitive types for <em>floating-point numbers</em>, which are
|
||
numbers with decimal points. Rust’s floating-point types are <code>f32</code> and <code>f64</code>,
|
||
which are 32 bits and 64 bits in size, respectively. The default type is <code>f64</code>
|
||
because on modern CPUs, it’s roughly the same speed as <code>f32</code> but is capable of
|
||
more precision. All floating-point types are signed.</p>
|
||
<p>Here’s an example that shows floating-point numbers in action:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let x = 2.0; // f64
|
||
|
||
let y: f32 = 3.0; // f32
|
||
}</code></pre>
|
||
<p>Floating-point numbers are represented according to the IEEE-754 standard.</p>
|
||
<h4 id="numeric-operations"><a class="header" href="#numeric-operations">Numeric Operations</a></h4>
|
||
<p>Rust supports the basic mathematical operations you’d expect for all the number
|
||
types: addition, subtraction, multiplication, division, and remainder. Integer
|
||
division truncates toward zero to the nearest integer. The following code shows
|
||
how you’d use each numeric operation in a <code>let</code> statement:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
// addition
|
||
let sum = 5 + 10;
|
||
|
||
// subtraction
|
||
let difference = 95.5 - 4.3;
|
||
|
||
// multiplication
|
||
let product = 4 * 30;
|
||
|
||
// division
|
||
let quotient = 56.7 / 32.2;
|
||
let truncated = -5 / 3; // Results in -1
|
||
|
||
// remainder
|
||
let remainder = 43 % 5;
|
||
}</code></pre>
|
||
<p>Each expression in these statements uses a mathematical operator and evaluates
|
||
to a single value, which is then bound to a variable. <a href="appendix-02-operators.html">Appendix
|
||
B</a><!-- ignore --> contains a list of all operators that Rust
|
||
provides.</p>
|
||
<h4 id="the-boolean-type"><a class="header" href="#the-boolean-type">The Boolean Type</a></h4>
|
||
<p>As in most other programming languages, a Boolean type in Rust has two possible
|
||
values: <code>true</code> and <code>false</code>. Booleans are one byte in size. The Boolean type in
|
||
Rust is specified using <code>bool</code>. For example:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let t = true;
|
||
|
||
let f: bool = false; // with explicit type annotation
|
||
}</code></pre>
|
||
<p>The main way to use Boolean values is through conditionals, such as an <code>if</code>
|
||
expression. We’ll cover how <code>if</code> expressions work in Rust in the <a href="ch03-05-control-flow.html#control-flow">“Control
|
||
Flow”</a><!-- ignore --> section.</p>
|
||
<h4 id="the-character-type"><a class="header" href="#the-character-type">The Character Type</a></h4>
|
||
<p>Rust’s <code>char</code> type is the language’s most primitive alphabetic type. Here are
|
||
some examples of declaring <code>char</code> values:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let c = 'z';
|
||
let z: char = 'ℤ'; // with explicit type annotation
|
||
let heart_eyed_cat = '😻';
|
||
}</code></pre>
|
||
<p>Note that we specify <code>char</code> literals with single quotation marks, as opposed to
|
||
string literals, which use double quotation marks. Rust’s <code>char</code> type is 4
|
||
bytes in size and represents a Unicode scalar value, which means it can
|
||
represent a lot more than just ASCII. Accented letters; Chinese, Japanese, and
|
||
Korean characters; emojis; and zero-width spaces are all valid <code>char</code> values in
|
||
Rust. Unicode scalar values range from <code>U+0000</code> to <code>U+D7FF</code> and <code>U+E000</code> to
|
||
<code>U+10FFFF</code> inclusive. However, a “character” isn’t really a concept in Unicode,
|
||
so your human intuition for what a “character” is may not match up with what a
|
||
<code>char</code> is in Rust. We’ll discuss this topic in detail in <a href="ch08-02-strings.html#storing-utf-8-encoded-text-with-strings">“Storing UTF-8
|
||
Encoded Text with Strings”</a><!-- ignore --> in Chapter 8.</p>
|
||
<h3 id="compound-types"><a class="header" href="#compound-types">Compound Types</a></h3>
|
||
<p><em>Compound types</em> can group multiple values into one type. Rust has two
|
||
primitive compound types: tuples and arrays.</p>
|
||
<h4 id="the-tuple-type"><a class="header" href="#the-tuple-type">The Tuple Type</a></h4>
|
||
<p>A <em>tuple</em> is a general way of grouping together a number of values with a
|
||
variety of types into one compound type. Tuples have a fixed length: Once
|
||
declared, they cannot grow or shrink in size.</p>
|
||
<p>We create a tuple by writing a comma-separated list of values inside
|
||
parentheses. Each position in the tuple has a type, and the types of the
|
||
different values in the tuple don’t have to be the same. We’ve added optional
|
||
type annotations in this example:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let tup: (i32, f64, u8) = (500, 6.4, 1);
|
||
}</code></pre>
|
||
<p>The variable <code>tup</code> binds to the entire tuple because a tuple is considered a
|
||
single compound element. To get the individual values out of a tuple, we can
|
||
use pattern matching to destructure a tuple value, like this:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let tup = (500, 6.4, 1);
|
||
|
||
let (x, y, z) = tup;
|
||
|
||
println!("The value of y is: {y}");
|
||
}</code></pre>
|
||
<p>This program first creates a tuple and binds it to the variable <code>tup</code>. It then
|
||
uses a pattern with <code>let</code> to take <code>tup</code> and turn it into three separate
|
||
variables, <code>x</code>, <code>y</code>, and <code>z</code>. This is called <em>destructuring</em> because it breaks
|
||
the single tuple into three parts. Finally, the program prints the value of
|
||
<code>y</code>, which is <code>6.4</code>.</p>
|
||
<p>We can also access a tuple element directly by using a period (<code>.</code>) followed by
|
||
the index of the value we want to access. For example:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let x: (i32, f64, u8) = (500, 6.4, 1);
|
||
|
||
let five_hundred = x.0;
|
||
|
||
let six_point_four = x.1;
|
||
|
||
let one = x.2;
|
||
}</code></pre>
|
||
<p>This program creates the tuple <code>x</code> and then accesses each element of the tuple
|
||
using their respective indices. As with most programming languages, the first
|
||
index in a tuple is 0.</p>
|
||
<p>The tuple without any values has a special name, <em>unit</em>. This value and its
|
||
corresponding type are both written <code>()</code> and represent an empty value or an
|
||
empty return type. Expressions implicitly return the unit value if they don’t
|
||
return any other value.</p>
|
||
<h4 id="the-array-type"><a class="header" href="#the-array-type">The Array Type</a></h4>
|
||
<p>Another way to have a collection of multiple values is with an <em>array</em>. Unlike
|
||
a tuple, every element of an array must have the same type. Unlike arrays in
|
||
some other languages, arrays in Rust have a fixed length.</p>
|
||
<p>We write the values in an array as a comma-separated list inside square
|
||
brackets:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let a = [1, 2, 3, 4, 5];
|
||
}</code></pre>
|
||
<p>Arrays are useful when you want your data allocated on the stack, the same as
|
||
the other types we have seen so far, rather than the heap (we will discuss the
|
||
stack and the heap more in <a href="ch04-01-what-is-ownership.html#the-stack-and-the-heap">Chapter 4</a><!-- ignore -->) or when
|
||
you want to ensure that you always have a fixed number of elements. An array
|
||
isn’t as flexible as the vector type, though. A vector is a similar collection
|
||
type provided by the standard library that <em>is</em> allowed to grow or shrink in
|
||
size because its contents live on the heap. If you’re unsure whether to use an
|
||
array or a vector, chances are you should use a vector. <a href="ch08-01-vectors.html">Chapter
|
||
8</a><!-- ignore --> discusses vectors in more detail.</p>
|
||
<p>However, arrays are more useful when you know the number of elements will not
|
||
need to change. For example, if you were using the names of the month in a
|
||
program, you would probably use an array rather than a vector because you know
|
||
it will always contain 12 elements:</p>
|
||
<pre class="playground"><code class="language-rust edition2024"><span class="boring">#![allow(unused)]
|
||
</span><span class="boring">fn main() {
|
||
</span>let months = ["January", "February", "March", "April", "May", "June", "July",
|
||
"August", "September", "October", "November", "December"];
|
||
<span class="boring">}</span></code></pre>
|
||
<p>You write an array’s type using square brackets with the type of each element,
|
||
a semicolon, and then the number of elements in the array, like so:</p>
|
||
<pre class="playground"><code class="language-rust edition2024"><span class="boring">#![allow(unused)]
|
||
</span><span class="boring">fn main() {
|
||
</span>let a: [i32; 5] = [1, 2, 3, 4, 5];
|
||
<span class="boring">}</span></code></pre>
|
||
<p>Here, <code>i32</code> is the type of each element. After the semicolon, the number <code>5</code>
|
||
indicates the array contains five elements.</p>
|
||
<p>You can also initialize an array to contain the same value for each element by
|
||
specifying the initial value, followed by a semicolon, and then the length of
|
||
the array in square brackets, as shown here:</p>
|
||
<pre class="playground"><code class="language-rust edition2024"><span class="boring">#![allow(unused)]
|
||
</span><span class="boring">fn main() {
|
||
</span>let a = [3; 5];
|
||
<span class="boring">}</span></code></pre>
|
||
<p>The array named <code>a</code> will contain <code>5</code> elements that will all be set to the value
|
||
<code>3</code> initially. This is the same as writing <code>let a = [3, 3, 3, 3, 3];</code> but in a
|
||
more concise way.</p>
|
||
<!-- Old headings. Do not remove or links may break. -->
|
||
<p><a id="accessing-array-elements"></a></p>
|
||
<h4 id="array-element-access"><a class="header" href="#array-element-access">Array Element Access</a></h4>
|
||
<p>An array is a single chunk of memory of a known, fixed size that can be
|
||
allocated on the stack. You can access elements of an array using indexing,
|
||
like this:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre class="playground"><code class="language-rust edition2024">fn main() {
|
||
let a = [1, 2, 3, 4, 5];
|
||
|
||
let first = a[0];
|
||
let second = a[1];
|
||
}</code></pre>
|
||
<p>In this example, the variable named <code>first</code> will get the value <code>1</code> because that
|
||
is the value at index <code>[0]</code> in the array. The variable named <code>second</code> will get
|
||
the value <code>2</code> from index <code>[1]</code> in the array.</p>
|
||
<h4 id="invalid-array-element-access"><a class="header" href="#invalid-array-element-access">Invalid Array Element Access</a></h4>
|
||
<p>Let’s see what happens if you try to access an element of an array that is past
|
||
the end of the array. Say you run this code, similar to the guessing game in
|
||
Chapter 2, to get an array index from the user:</p>
|
||
<p><span class="filename">Filename: src/main.rs</span></p>
|
||
<pre><code class="language-rust ignore panics">use std::io;
|
||
|
||
fn main() {
|
||
let a = [1, 2, 3, 4, 5];
|
||
|
||
println!("Please enter an array index.");
|
||
|
||
let mut index = String::new();
|
||
|
||
io::stdin()
|
||
.read_line(&mut index)
|
||
.expect("Failed to read line");
|
||
|
||
let index: usize = index
|
||
.trim()
|
||
.parse()
|
||
.expect("Index entered was not a number");
|
||
|
||
let element = a[index];
|
||
|
||
println!("The value of the element at index {index} is: {element}");
|
||
}</code></pre>
|
||
<p>This code compiles successfully. If you run this code using <code>cargo run</code> and
|
||
enter <code>0</code>, <code>1</code>, <code>2</code>, <code>3</code>, or <code>4</code>, the program will print out the corresponding
|
||
value at that index in the array. If you instead enter a number past the end of
|
||
the array, such as <code>10</code>, you’ll see output like this:</p>
|
||
<!-- manual-regeneration
|
||
cd listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access
|
||
cargo run
|
||
10
|
||
-->
|
||
<pre><code class="language-console">thread 'main' panicked at src/main.rs:19:19:
|
||
index out of bounds: the len is 5 but the index is 10
|
||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||
</code></pre>
|
||
<p>The program resulted in a runtime error at the point of using an invalid
|
||
value in the indexing operation. The program exited with an error message and
|
||
didn’t execute the final <code>println!</code> statement. When you attempt to access an
|
||
element using indexing, Rust will check that the index you’ve specified is less
|
||
than the array length. If the index is greater than or equal to the length,
|
||
Rust will panic. This check has to happen at runtime, especially in this case,
|
||
because the compiler can’t possibly know what value a user will enter when they
|
||
run the code later.</p>
|
||
<p>This is an example of Rust’s memory safety principles in action. In many
|
||
low-level languages, this kind of check is not done, and when you provide an
|
||
incorrect index, invalid memory can be accessed. Rust protects you against this
|
||
kind of error by immediately exiting instead of allowing the memory access and
|
||
continuing. Chapter 9 discusses more of Rust’s error handling and how you can
|
||
write readable, safe code that neither panics nor allows invalid memory access.</p>
|
||
|
||
</main>
|
||
|
||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||
<!-- Mobile navigation buttons -->
|
||
<a rel="prev" href="ch03-01-variables-and-mutability.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg></span>
|
||
</a>
|
||
|
||
<a rel="next prefetch" href="ch03-03-how-functions-work.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"/></svg></span>
|
||
</a>
|
||
|
||
<div style="clear: both"></div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||
<a rel="prev" href="ch03-01-variables-and-mutability.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"/></svg></span>
|
||
</a>
|
||
|
||
<a rel="next prefetch" href="ch03-03-how-functions-work.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||
<span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"/></svg></span>
|
||
</a>
|
||
</nav>
|
||
|
||
</div>
|
||
|
||
<template id=fa-eye><span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM432 256c0 79.5-64.5 144-144 144s-144-64.5-144-144s64.5-144 144-144s144 64.5 144 144zM288 192c0 35.3-28.7 64-64 64c-11.5 0-22.3-3-31.6-8.4c-.2 2.8-.4 5.5-.4 8.4c0 53 43 96 96 96s96-43 96-96s-43-96-96-96c-2.8 0-5.6 .1-8.4 .4c5.3 9.3 8.4 20.1 8.4 31.6z"/></svg></span></template>
|
||
<template id=fa-eye-slash><span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2S-1.2 34.7 9.2 42.9l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7L525.6 386.7c39.6-40.6 66.4-86.1 79.9-118.4c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C465.5 68.8 400.8 32 320 32c-68.2 0-125 26.3-169.3 60.8L38.8 5.1zM223.1 149.5C248.6 126.2 282.7 112 320 112c79.5 0 144 64.5 144 144c0 24.9-6.3 48.3-17.4 68.7L408 294.5c5.2-11.8 8-24.8 8-38.5c0-53-43-96-96-96c-2.8 0-5.6 .1-8.4 .4c5.3 9.3 8.4 20.1 8.4 31.6c0 10.2-2.4 19.8-6.6 28.3l-90.3-70.8zm223.1 298L373 389.9c-16.4 6.5-34.3 10.1-53 10.1c-79.5 0-144-64.5-144-144c0-6.9 .5-13.6 1.4-20.2L83.1 161.5C60.3 191.2 44 220.8 34.5 243.7c-3.3 7.9-3.3 16.7 0 24.6c14.9 35.7 46.2 87.7 93 131.1C174.5 443.2 239.2 480 320 480c47.8 0 89.9-12.9 126.2-32.5z"/></svg></span></template>
|
||
<template id=fa-copy><span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M502.6 70.63l-61.25-61.25C435.4 3.371 427.2 0 418.7 0H255.1c-35.35 0-64 28.66-64 64l.0195 256C192 355.4 220.7 384 256 384h192c35.2 0 64-28.8 64-64V93.25C512 84.77 508.6 76.63 502.6 70.63zM464 320c0 8.836-7.164 16-16 16H255.1c-8.838 0-16-7.164-16-16L239.1 64.13c0-8.836 7.164-16 16-16h128L384 96c0 17.67 14.33 32 32 32h47.1V320zM272 448c0 8.836-7.164 16-16 16H63.1c-8.838 0-16-7.164-16-16L47.98 192.1c0-8.836 7.164-16 16-16H160V128H63.99c-35.35 0-64 28.65-64 64l.0098 256C.002 483.3 28.66 512 64 512h192c35.2 0 64-28.8 64-64v-32h-47.1L272 448z"/></svg></span></template>
|
||
<template id=fa-play><span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80V432c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9L361 297c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39z"/></svg></span></template>
|
||
<template id=fa-clock-rotate-left><span class=fa-svg><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M75 75L41 41C25.9 25.9 0 36.6 0 57.9V168c0 13.3 10.7 24 24 24H134.1c21.4 0 32.1-25.9 17-41l-30.8-30.8C155 85.5 203 64 256 64c106 0 192 86 192 192s-86 192-192 192c-40.8 0-78.6-12.7-109.7-34.4c-14.5-10.1-34.4-6.6-44.6 7.9s-6.6 34.4 7.9 44.6C151.2 495 201.7 512 256 512c141.4 0 256-114.6 256-256S397.4 0 256 0C185.3 0 121.3 28.7 75 75zm181 53c-13.3 0-24 10.7-24 24V256c0 6.4 2.5 12.5 7 17l72 72c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-65-65V152c0-13.3-10.7-24-24-24z"/></svg></span></template>
|
||
|
||
|
||
|
||
<script>
|
||
window.playground_copyable = true;
|
||
</script>
|
||
|
||
|
||
<script src="elasticlunr-ef4e11c1.min.js"></script>
|
||
<script src="mark-09e88c2c.min.js"></script>
|
||
<script src="searcher-09f2665d.js"></script>
|
||
|
||
<script src="clipboard-1626706a.min.js"></script>
|
||
<script src="highlight-abc7f01d.js"></script>
|
||
<script src="book-c22b7243.js"></script>
|
||
|
||
<!-- Custom JS scripts -->
|
||
<script src="ferris-2317480c.js"></script>
|
||
|
||
|
||
|
||
</div>
|
||
</body>
|
||
</html>
|