]> git.lizzy.rs Git - rust.git/blob - src/libstd/num/u32.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / libstd / num / u32.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Operations and constants for unsigned 32-bits integers (`u32` type)
12
13 #![allow(non_uppercase_statics)]
14
15 use prelude::*;
16
17 use default::Default;
18 use from_str::FromStr;
19 use num::{Bitwise, Bounded};
20 use num::{CheckedAdd, CheckedSub, CheckedMul};
21 use num::{CheckedDiv, Zero, One, strconv};
22 use num::{ToStrRadix, FromStrRadix};
23 use option::{Option, Some, None};
24 use str;
25 use intrinsics;
26
27 uint_module!(u32, i32, 32)
28
29 impl CheckedAdd for u32 {
30     #[inline]
31     fn checked_add(&self, v: &u32) -> Option<u32> {
32         unsafe {
33             let (x, y) = intrinsics::u32_add_with_overflow(*self, *v);
34             if y { None } else { Some(x) }
35         }
36     }
37 }
38
39 impl CheckedSub for u32 {
40     #[inline]
41     fn checked_sub(&self, v: &u32) -> Option<u32> {
42         unsafe {
43             let (x, y) = intrinsics::u32_sub_with_overflow(*self, *v);
44             if y { None } else { Some(x) }
45         }
46     }
47 }
48
49 impl CheckedMul for u32 {
50     #[inline]
51     fn checked_mul(&self, v: &u32) -> Option<u32> {
52         unsafe {
53             let (x, y) = intrinsics::u32_mul_with_overflow(*self, *v);
54             if y { None } else { Some(x) }
55         }
56     }
57 }