blob: 4469a8c2a3cc8093ca80c6916de7f4ad892a1b50 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Performs an integral remainder that returns `None` instead of panicking on division by zero and instead of wrapping around on underflow and overflow."><meta name="keywords" content="rust, rustlang, rust-lang, CheckedRem"><title>CheckedRem in num::traits::ops::checked - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../../../normalize.css"><link rel="stylesheet" href="../../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../../../ayu.css" disabled><link rel="stylesheet" href="../../../../dark.css" disabled><link rel="stylesheet" href="../../../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../main.js"></script><noscript><link rel="stylesheet" href="../../../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../../../favicon.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../../../../num/index.html"><div class="logo-container"><img class="rust-logo" src="../../../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../../../num/index.html"><div class="logo-container"><img class="rust-logo" src="../../../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">CheckedRem</a></h2><div class="sidebar-elems"><section><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.checked_rem">checked_rem</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-CheckedRem-for-i128">i128</a></li><li><a href="#impl-CheckedRem-for-i16">i16</a></li><li><a href="#impl-CheckedRem-for-i32">i32</a></li><li><a href="#impl-CheckedRem-for-i64">i64</a></li><li><a href="#impl-CheckedRem-for-i8">i8</a></li><li><a href="#impl-CheckedRem-for-isize">isize</a></li><li><a href="#impl-CheckedRem-for-u128">u128</a></li><li><a href="#impl-CheckedRem-for-u16">u16</a></li><li><a href="#impl-CheckedRem-for-u32">u32</a></li><li><a href="#impl-CheckedRem-for-u64">u64</a></li><li><a href="#impl-CheckedRem-for-u8">u8</a></li><li><a href="#impl-CheckedRem-for-usize">usize</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In num::traits::ops::checked</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../../../index.html">num</a>::<wbr><a href="../../index.html">traits</a>::<wbr><a href="../index.html">ops</a>::<wbr><a href="index.html">checked</a>::<wbr><a class="trait" href="#">CheckedRem</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../../../src/num_traits/ops/checked.rs.html#111">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait CheckedRem: Rem&lt;Self, Output = Self&gt; {
fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;Self) -&gt; Option&lt;Self&gt;;
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Performs an integral remainder that returns <code>None</code> instead of panicking on division by zero and
instead of wrapping around on underflow and overflow.</p>
</div></details><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.checked_rem" class="method has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#131">source</a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;Self) -&gt; Option&lt;Self&gt;</h4></section></summary><div class="docblock"><p>Finds the remainder of dividing two numbers, checking for underflow, overflow and division
by zero. If any of that happens, <code>None</code> is returned.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>num_traits::CheckedRem;
<span class="kw">use </span>std::i32::MIN;
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span><span class="number">10</span>, <span class="kw-2">&amp;</span><span class="number">7</span>), <span class="prelude-val">Some</span>(<span class="number">3</span>));
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span><span class="number">10</span>, <span class="kw-2">&amp;</span>-<span class="number">7</span>), <span class="prelude-val">Some</span>(<span class="number">3</span>));
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span>-<span class="number">10</span>, <span class="kw-2">&amp;</span><span class="number">7</span>), <span class="prelude-val">Some</span>(-<span class="number">3</span>));
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span>-<span class="number">10</span>, <span class="kw-2">&amp;</span>-<span class="number">7</span>), <span class="prelude-val">Some</span>(-<span class="number">3</span>));
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span><span class="number">10</span>, <span class="kw-2">&amp;</span><span class="number">0</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span>MIN, <span class="kw-2">&amp;</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="number">0</span>));
<span class="macro">assert_eq!</span>(CheckedRem::checked_rem(<span class="kw-2">&amp;</span>MIN, <span class="kw-2">&amp;</span>-<span class="number">1</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details></div><h2 id="foreign-impls" class="small-section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor"></a></h2><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-u128" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#140">source</a><a href="#impl-CheckedRem-for-u128" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for u128</h3></section></summary><div class="impl-items"><section id="method.checked_rem" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#140">source</a><a href="#method.checked_rem" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;u128) -&gt; Option&lt;u128&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-i128" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#148">source</a><a href="#impl-CheckedRem-for-i128" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for i128</h3></section></summary><div class="impl-items"><section id="method.checked_rem-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#148">source</a><a href="#method.checked_rem-1" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;i128) -&gt; Option&lt;i128&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-i8" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#142">source</a><a href="#impl-CheckedRem-for-i8" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for i8</h3></section></summary><div class="impl-items"><section id="method.checked_rem-2" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#142">source</a><a href="#method.checked_rem-2" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;i8) -&gt; Option&lt;i8&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-isize" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#146">source</a><a href="#impl-CheckedRem-for-isize" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for isize</h3></section></summary><div class="impl-items"><section id="method.checked_rem-3" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#146">source</a><a href="#method.checked_rem-3" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;isize) -&gt; Option&lt;isize&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-usize" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#138">source</a><a href="#impl-CheckedRem-for-usize" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for usize</h3></section></summary><div class="impl-items"><section id="method.checked_rem-4" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#138">source</a><a href="#method.checked_rem-4" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;usize) -&gt; Option&lt;usize&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-i16" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#143">source</a><a href="#impl-CheckedRem-for-i16" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for i16</h3></section></summary><div class="impl-items"><section id="method.checked_rem-5" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#143">source</a><a href="#method.checked_rem-5" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;i16) -&gt; Option&lt;i16&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-u8" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#134">source</a><a href="#impl-CheckedRem-for-u8" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for u8</h3></section></summary><div class="impl-items"><section id="method.checked_rem-6" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#134">source</a><a href="#method.checked_rem-6" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;u8) -&gt; Option&lt;u8&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-i32" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#144">source</a><a href="#impl-CheckedRem-for-i32" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for i32</h3></section></summary><div class="impl-items"><section id="method.checked_rem-7" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#144">source</a><a href="#method.checked_rem-7" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;i32) -&gt; Option&lt;i32&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-u32" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#136">source</a><a href="#impl-CheckedRem-for-u32" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for u32</h3></section></summary><div class="impl-items"><section id="method.checked_rem-8" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#136">source</a><a href="#method.checked_rem-8" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;u32) -&gt; Option&lt;u32&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-u64" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#137">source</a><a href="#impl-CheckedRem-for-u64" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for u64</h3></section></summary><div class="impl-items"><section id="method.checked_rem-9" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#137">source</a><a href="#method.checked_rem-9" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;u64) -&gt; Option&lt;u64&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-i64" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#145">source</a><a href="#impl-CheckedRem-for-i64" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for i64</h3></section></summary><div class="impl-items"><section id="method.checked_rem-10" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#145">source</a><a href="#method.checked_rem-10" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;i64) -&gt; Option&lt;i64&gt;</h4></section></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-CheckedRem-for-u16" class="impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#135">source</a><a href="#impl-CheckedRem-for-u16" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../../trait.CheckedRem.html" title="trait num::traits::CheckedRem">CheckedRem</a> for u16</h3></section></summary><div class="impl-items"><section id="method.checked_rem-11" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../../src/num_traits/ops/checked.rs.html#135">source</a><a href="#method.checked_rem-11" class="anchor"></a><h4 class="code-header">fn <a href="#tymethod.checked_rem" class="fnname">checked_rem</a>(&amp;self, v: &amp;u16) -&gt; Option&lt;u16&gt;</h4></section></div></details><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"></div><script src="../../../../implementors/num_traits/ops/checked/trait.CheckedRem.js" data-ignore-extern-crates="core" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../../../" data-current-crate="num" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>