scad 1.2.2

A crate for generating OpenSCAD models using rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<!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="API documentation for the Rust `PrimInt` trait in crate `num`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, PrimInt">

    <title>num::PrimInt - Rust</title>

    <link rel="stylesheet" type="text/css" href="../rustdoc.css">
    <link rel="stylesheet" type="text/css" href="../main.css">
    

    <link rel="shortcut icon" href="http://rust-num.github.io/num/favicon.ico">
    
</head>
<body class="rustdoc">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    

    <nav class="sidebar">
        <a href='../num/index.html'><img src='http://rust-num.github.io/num/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
        <p class='location'><a href='index.html'>num</a></p><script>window.sidebarCurrent = {name: 'PrimInt', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script>
    </nav>

    <nav class="sub">
        <form class="search-form js-only">
            <div class="search-container">
                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
                       type="search">
            </div>
        </form>
    </nav>

    <section id='main' class="content trait">
<h1 class='fqn'><span class='in-band'>Trait <a href='index.html'>num</a>::<wbr><a class='trait' href=''>PrimInt</a></span><span class='out-of-band'><span id='render-detail'>
                   <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
                       [<span class='inner'>&#x2212;</span>]
                   </a>
               </span><a id='src-2026' class='srclink' href='../num_traits/int/trait.PrimInt.html?gotosrc=2026' title='goto source code'>[src]</a></span></h1>
<pre class='rust trait'>pub trait PrimInt: <a class='trait' href='https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html' title='core::marker::Copy'>Copy</a> + <a class='trait' href='../num/traits/trait.Saturating.html' title='num::traits::Saturating'>Saturating</a> + <a class='trait' href='../num/traits/trait.CheckedAdd.html' title='num::traits::CheckedAdd'>CheckedAdd</a>&lt;Output=Self&gt; + <a class='trait' href='../num/traits/trait.CheckedSub.html' title='num::traits::CheckedSub'>CheckedSub</a>&lt;Output=Self&gt; + <a class='trait' href='../num/traits/trait.CheckedMul.html' title='num::traits::CheckedMul'>CheckedMul</a>&lt;Output=Self&gt; + <a class='trait' href='../num/traits/trait.CheckedDiv.html' title='num::traits::CheckedDiv'>CheckedDiv</a>&lt;Output=Self&gt; + <a class='trait' href='../num/traits/trait.Bounded.html' title='num::traits::Bounded'>Bounded</a> + <a class='trait' href='../num/traits/trait.NumCast.html' title='num::traits::NumCast'>NumCast</a> + <a class='trait' href='../num/traits/trait.Num.html' title='num::traits::Num'>Num</a> + <a class='trait' href='https://doc.rust-lang.org/nightly/core/ops/trait.Not.html' title='core::ops::Not'>Not</a>&lt;Output=Self&gt; + <a class='trait' href='https://doc.rust-lang.org/nightly/core/ops/trait.BitAnd.html' title='core::ops::BitAnd'>BitAnd</a>&lt;Self,&nbsp;Output=Self&gt; + <a class='trait' href='https://doc.rust-lang.org/nightly/core/ops/trait.BitOr.html' title='core::ops::BitOr'>BitOr</a>&lt;Self,&nbsp;Output=Self&gt; + <a class='trait' href='https://doc.rust-lang.org/nightly/core/ops/trait.BitXor.html' title='core::ops::BitXor'>BitXor</a>&lt;Self,&nbsp;Output=Self&gt; + <a class='trait' href='https://doc.rust-lang.org/nightly/core/ops/trait.Shl.html' title='core::ops::Shl'>Shl</a>&lt;<a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>,&nbsp;Output=Self&gt; + <a class='trait' href='https://doc.rust-lang.org/nightly/core/ops/trait.Shr.html' title='core::ops::Shr'>Shr</a>&lt;<a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a>,&nbsp;Output=Self&gt; + <a class='trait' href='https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html' title='core::cmp::Eq'>Eq</a> + <a class='trait' href='https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html' title='core::cmp::Ord'>Ord</a> + <a class='trait' href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html' title='core::cmp::PartialOrd'>PartialOrd</a>&lt;Self&gt; {
    fn <a href='#tymethod.count_ones' class='fnname'>count_ones</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>;
    fn <a href='#tymethod.count_zeros' class='fnname'>count_zeros</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>;
    fn <a href='#tymethod.leading_zeros' class='fnname'>leading_zeros</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>;
    fn <a href='#tymethod.trailing_zeros' class='fnname'>trailing_zeros</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>;
    fn <a href='#tymethod.rotate_left' class='fnname'>rotate_left</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
    fn <a href='#tymethod.rotate_right' class='fnname'>rotate_right</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
    fn <a href='#tymethod.signed_shl' class='fnname'>signed_shl</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
    fn <a href='#tymethod.signed_shr' class='fnname'>signed_shr</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
    fn <a href='#tymethod.unsigned_shl' class='fnname'>unsigned_shl</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
    fn <a href='#tymethod.unsigned_shr' class='fnname'>unsigned_shr</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
    fn <a href='#tymethod.swap_bytes' class='fnname'>swap_bytes</a>(self) -&gt; Self;
    fn <a href='#tymethod.from_be' class='fnname'>from_be</a>(x: Self) -&gt; Self;
    fn <a href='#tymethod.from_le' class='fnname'>from_le</a>(x: Self) -&gt; Self;
    fn <a href='#tymethod.to_be' class='fnname'>to_be</a>(self) -&gt; Self;
    fn <a href='#tymethod.to_le' class='fnname'>to_le</a>(self) -&gt; Self;
    fn <a href='#tymethod.pow' class='fnname'>pow</a>(self, exp: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self;
}</pre>
            <h2 id='required-methods'>Required Methods</h2>
            <div class='methods'>
        <h3 id='tymethod.count_ones' class='method stab '><span id='count_ones.v' class='invisible'><code>fn <a href='#tymethod.count_ones' class='fnname'>count_ones</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a></code></span></h3><div class='docblock'><p>Returns the number of ones in the binary representation of <code>self</code>.</p>

<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0b01001100u8;

assert_eq!(n.count_ones(), 3);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0b01001100u8</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>count_ones</span>(), <span class='number'>3</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.count_zeros' class='method stab '><span id='count_zeros.v' class='invisible'><code>fn <a href='#tymethod.count_zeros' class='fnname'>count_zeros</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a></code></span></h3><div class='docblock'><p>Returns the number of zeros in the binary representation of <code>self</code>.</p>

<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0b01001100u8;

assert_eq!(n.count_zeros(), 5);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0b01001100u8</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>count_zeros</span>(), <span class='number'>5</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.leading_zeros' class='method stab '><span id='leading_zeros.v' class='invisible'><code>fn <a href='#tymethod.leading_zeros' class='fnname'>leading_zeros</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a></code></span></h3><div class='docblock'><p>Returns the number of leading zeros in the binary representation
of <code>self</code>.</p>

<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0b0101000u16;

assert_eq!(n.leading_zeros(), 10);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0b0101000u16</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>leading_zeros</span>(), <span class='number'>10</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.trailing_zeros' class='method stab '><span id='trailing_zeros.v' class='invisible'><code>fn <a href='#tymethod.trailing_zeros' class='fnname'>trailing_zeros</a>(self) -&gt; <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a></code></span></h3><div class='docblock'><p>Returns the number of trailing zeros in the binary representation
of <code>self</code>.</p>

<h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0b0101000u16;

assert_eq!(n.trailing_zeros(), 3);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0b0101000u16</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>trailing_zeros</span>(), <span class='number'>3</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.rotate_left' class='method stab '><span id='rotate_left.v' class='invisible'><code>fn <a href='#tymethod.rotate_left' class='fnname'>rotate_left</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the left by a specified amount amount, <code>n</code>, wrapping
the truncated bits to the end of the resulting integer.</p>

<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;
let m = 0x3456789ABCDEF012u64;

assert_eq!(n.rotate_left(12), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0x3456789ABCDEF012u64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>rotate_left</span>(<span class='number'>12</span>), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.rotate_right' class='method stab '><span id='rotate_right.v' class='invisible'><code>fn <a href='#tymethod.rotate_right' class='fnname'>rotate_right</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the right by a specified amount amount, <code>n</code>, wrapping
the truncated bits to the beginning of the resulting integer.</p>

<h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;
let m = 0xDEF0123456789ABCu64;

assert_eq!(n.rotate_right(12), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0xDEF0123456789ABCu64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>rotate_right</span>(<span class='number'>12</span>), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.signed_shl' class='method stab '><span id='signed_shl.v' class='invisible'><code>fn <a href='#tymethod.signed_shl' class='fnname'>signed_shl</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the left by a specified amount amount, <code>n</code>, filling
zeros in the least significant bits.</p>

<p>This is bitwise equivalent to signed <code>Shl</code>.</p>

<h1 id='examples-6' class='section-header'><a href='#examples-6'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;
let m = 0x3456789ABCDEF000u64;

assert_eq!(n.signed_shl(12), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0x3456789ABCDEF000u64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>signed_shl</span>(<span class='number'>12</span>), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.signed_shr' class='method stab '><span id='signed_shr.v' class='invisible'><code>fn <a href='#tymethod.signed_shr' class='fnname'>signed_shr</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the right by a specified amount amount, <code>n</code>, copying
the &quot;sign bit&quot; in the most significant bits even for unsigned types.</p>

<p>This is bitwise equivalent to signed <code>Shr</code>.</p>

<h1 id='examples-7' class='section-header'><a href='#examples-7'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0xFEDCBA9876543210u64;
let m = 0xFFFFEDCBA9876543u64;

assert_eq!(n.signed_shr(12), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0xFEDCBA9876543210u64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0xFFFFEDCBA9876543u64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>signed_shr</span>(<span class='number'>12</span>), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.unsigned_shl' class='method stab '><span id='unsigned_shl.v' class='invisible'><code>fn <a href='#tymethod.unsigned_shl' class='fnname'>unsigned_shl</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the left by a specified amount amount, <code>n</code>, filling
zeros in the least significant bits.</p>

<p>This is bitwise equivalent to unsigned <code>Shl</code>.</p>

<h1 id='examples-8' class='section-header'><a href='#examples-8'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFi64;
let m = 0x3456789ABCDEF000i64;

assert_eq!(n.unsigned_shl(12), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFi64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0x3456789ABCDEF000i64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>unsigned_shl</span>(<span class='number'>12</span>), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.unsigned_shr' class='method stab '><span id='unsigned_shr.v' class='invisible'><code>fn <a href='#tymethod.unsigned_shr' class='fnname'>unsigned_shr</a>(self, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the right by a specified amount amount, <code>n</code>, filling
zeros in the most significant bits.</p>

<p>This is bitwise equivalent to unsigned <code>Shr</code>.</p>

<h1 id='examples-9' class='section-header'><a href='#examples-9'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0xFEDCBA9876543210i64;
let m = 0x000FEDCBA9876543i64;

assert_eq!(n.unsigned_shr(12), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0xFEDCBA9876543210i64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0x000FEDCBA9876543i64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>unsigned_shr</span>(<span class='number'>12</span>), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.swap_bytes' class='method stab '><span id='swap_bytes.v' class='invisible'><code>fn <a href='#tymethod.swap_bytes' class='fnname'>swap_bytes</a>(self) -&gt; Self</code></span></h3><div class='docblock'><p>Reverses the byte order of the integer.</p>

<h1 id='examples-10' class='section-header'><a href='#examples-10'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;
let m = 0xEFCDAB8967452301u64;

assert_eq!(n.swap_bytes(), m);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;
<span class='kw'>let</span> <span class='ident'>m</span> <span class='op'>=</span> <span class='number'>0xEFCDAB8967452301u64</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>swap_bytes</span>(), <span class='ident'>m</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.from_be' class='method stab '><span id='from_be.v' class='invisible'><code>fn <a href='#tymethod.from_be' class='fnname'>from_be</a>(x: Self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert an integer from big endian to the target&#39;s endianness.</p>

<p>On big endian this is a no-op. On little endian the bytes are swapped.</p>

<h1 id='examples-11' class='section-header'><a href='#examples-11'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;

if cfg!(target_endian = &quot;big&quot;) {
    assert_eq!(u64::from_be(n), n)
} else {
    assert_eq!(u64::from_be(n), n.swap_bytes())
}
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;

<span class='kw'>if</span> <span class='macro'>cfg</span><span class='macro'>!</span>(<span class='ident'>target_endian</span> <span class='op'>=</span> <span class='string'>&quot;big&quot;</span>) {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>u64</span>::<span class='ident'>from_be</span>(<span class='ident'>n</span>), <span class='ident'>n</span>)
} <span class='kw'>else</span> {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>u64</span>::<span class='ident'>from_be</span>(<span class='ident'>n</span>), <span class='ident'>n</span>.<span class='ident'>swap_bytes</span>())
}<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.from_le' class='method stab '><span id='from_le.v' class='invisible'><code>fn <a href='#tymethod.from_le' class='fnname'>from_le</a>(x: Self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert an integer from little endian to the target&#39;s endianness.</p>

<p>On little endian this is a no-op. On big endian the bytes are swapped.</p>

<h1 id='examples-12' class='section-header'><a href='#examples-12'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;

if cfg!(target_endian = &quot;little&quot;) {
    assert_eq!(u64::from_le(n), n)
} else {
    assert_eq!(u64::from_le(n), n.swap_bytes())
}
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;

<span class='kw'>if</span> <span class='macro'>cfg</span><span class='macro'>!</span>(<span class='ident'>target_endian</span> <span class='op'>=</span> <span class='string'>&quot;little&quot;</span>) {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>u64</span>::<span class='ident'>from_le</span>(<span class='ident'>n</span>), <span class='ident'>n</span>)
} <span class='kw'>else</span> {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>u64</span>::<span class='ident'>from_le</span>(<span class='ident'>n</span>), <span class='ident'>n</span>.<span class='ident'>swap_bytes</span>())
}<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.to_be' class='method stab '><span id='to_be.v' class='invisible'><code>fn <a href='#tymethod.to_be' class='fnname'>to_be</a>(self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert <code>self</code> to big endian from the target&#39;s endianness.</p>

<p>On big endian this is a no-op. On little endian the bytes are swapped.</p>

<h1 id='examples-13' class='section-header'><a href='#examples-13'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;

if cfg!(target_endian = &quot;big&quot;) {
    assert_eq!(n.to_be(), n)
} else {
    assert_eq!(n.to_be(), n.swap_bytes())
}
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;

<span class='kw'>if</span> <span class='macro'>cfg</span><span class='macro'>!</span>(<span class='ident'>target_endian</span> <span class='op'>=</span> <span class='string'>&quot;big&quot;</span>) {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>to_be</span>(), <span class='ident'>n</span>)
} <span class='kw'>else</span> {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>to_be</span>(), <span class='ident'>n</span>.<span class='ident'>swap_bytes</span>())
}<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.to_le' class='method stab '><span id='to_le.v' class='invisible'><code>fn <a href='#tymethod.to_le' class='fnname'>to_le</a>(self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert <code>self</code> to little endian from the target&#39;s endianness.</p>

<p>On little endian this is a no-op. On big endian the bytes are swapped.</p>

<h1 id='examples-14' class='section-header'><a href='#examples-14'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

let n = 0x0123456789ABCDEFu64;

if cfg!(target_endian = &quot;little&quot;) {
    assert_eq!(n.to_le(), n)
} else {
    assert_eq!(n.to_le(), n.swap_bytes())
}
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='number'>0x0123456789ABCDEFu64</span>;

<span class='kw'>if</span> <span class='macro'>cfg</span><span class='macro'>!</span>(<span class='ident'>target_endian</span> <span class='op'>=</span> <span class='string'>&quot;little&quot;</span>) {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>to_le</span>(), <span class='ident'>n</span>)
} <span class='kw'>else</span> {
    <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>n</span>.<span class='ident'>to_le</span>(), <span class='ident'>n</span>.<span class='ident'>swap_bytes</span>())
}<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div><h3 id='tymethod.pow' class='method stab '><span id='pow.v' class='invisible'><code>fn <a href='#tymethod.pow' class='fnname'>pow</a>(self, exp: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Raises self to the power of <code>exp</code>, using exponentiation by squaring.</p>

<h1 id='examples-15' class='section-header'><a href='#examples-15'>Examples</a></h1>
<span class='rusttest'>extern crate num;
fn main() {
    use num_traits::PrimInt;

assert_eq!(2i32.pow(4), 16);
}</span><pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>num_traits</span>::<span class='ident'>PrimInt</span>;

<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='number'>2i32</span>.<span class='ident'>pow</span>(<span class='number'>4</span>), <span class='number'>16</span>);<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div></div>
        <h2 id='implementors'>Implementors</h2>
        <ul class='item-list' id='implementors-list'>
    <li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u16.html'>u16</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u32.html'>u32</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u64.html'>u64</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.usize.html'>usize</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.i8.html'>i8</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.i16.html'>i16</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.i32.html'>i32</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.i64.html'>i64</a></code></li>
<li><code>impl PrimInt for <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.isize.html'>isize</a></code></li>
</ul><script type="text/javascript" async
                         src="../implementors/num_traits/int/trait.PrimInt.js">
                 </script></section>
    <section id='search' class="content hidden"></section>

    <section class="footer"></section>

    <aside id="help" class="hidden">
        <div>
            <h1 class="hidden">Help</h1>

            <div class="shortcuts">
                <h2>Keyboard Shortcuts</h2>

                <dl>
                    <dt>?</dt>
                    <dd>Show this help dialog</dd>
                    <dt>S</dt>
                    <dd>Focus the search field</dd>
                    <dt>&larrb;</dt>
                    <dd>Move up in search results</dd>
                    <dt>&rarrb;</dt>
                    <dd>Move down in search results</dd>
                    <dt>&#9166;</dt>
                    <dd>Go to active search result</dd>
                    <dt>+</dt>
                    <dd>Collapse/expand all sections</dd>
                </dl>
            </div>

            <div class="infos">
                <h2>Search Tricks</h2>

                <p>
                    Prefix searches with a type followed by a colon (e.g.
                    <code>fn:</code>) to restrict the search to a given type.
                </p>

                <p>
                    Accepted types are: <code>fn</code>, <code>mod</code>,
                    <code>struct</code>, <code>enum</code>,
                    <code>trait</code>, <code>type</code>, <code>macro</code>,
                    and <code>const</code>.
                </p>

                <p>
                    Search functions by type signature (e.g.
                    <code>vec -> usize</code> or <code>* -> vec</code>)
                </p>
            </div>
        </div>
    </aside>

    

    <script>
        window.rootPath = "../";
        window.currentCrate = "num";
        window.playgroundUrl = "http://play.rust-lang.org/";
    </script>
    <script src="../jquery.js"></script>
    <script src="../main.js"></script>
    <script src="../playpen.js"></script>
    <script defer src="../search-index.js"></script>
</body>
</html>