| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{ |
| 2 | convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#, |
| 3 | iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/, |
| 4 | opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#, AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#, Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#, DivAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/DivAssign#, Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#, MulAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/MulAssign#, Remrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Rem#, RemAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/RemAssign#, Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#, SubAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#}, |
| 5 | strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#, |
| 6 | }; |
| 7 | |
| 8 | #[cfg(feature = "serde")] |
| 9 | use serderust-analyzer cargo serde 1.0.229 crate/::{ |
| 10 | derust-analyzer cargo serde_core 1.0.229 de/::{Errorrust-analyzer cargo serde_core 1.0.229 de/Error# as _, Unexpectedrust-analyzer cargo serde_core 1.0.229 de/Unexpected#}, |
| 11 | Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#, Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 12 | }; |
| 13 | |
| 14 | use craterust-analyzer cargo js_int 0.2.2 crate/::{ |
| 15 | errorrust-analyzer cargo js_int 0.2.2 error/::{ParseIntErrorrust-analyzer cargo js_int 0.2.2 error/ParseIntError#, ParseIntErrorKindrust-analyzer cargo js_int 0.2.2 error/ParseIntErrorKind#, TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#}, |
| 16 | MAX_SAFE_INTrust-analyzer cargo js_int 0.2.2 int/MAX_SAFE_INT., |
| 17 | }; |
| 18 | |
| 19 | /// The same as `MAX_SAFE_INT`, but with `u64` as the type. |
| 20 | pub const MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.: u64 = 0x001F_FFFF_FFFF_FFFF; |
| 21 | |
| 22 | /// An integer limited to the range of non-negative integers that can be represented exactly by an |
| 23 | /// f64. |
| 24 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 25 | #[cfg_attr(feature = "serde", derive(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:))] |
| 26 | pub struct UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(u64); |
| 27 | |
| 28 | impl UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 29 | /// The smallest value that can be represented by this integer type. |
| 30 | /// |
| 31 | /// # Examples |
| 32 | /// |
| 33 | /// Basic usage: |
| 34 | /// |
| 35 | /// ``` |
| 36 | /// # use js_int::{uint, UInt}; |
| 37 | /// assert_eq!(UInt::MIN, uint!(0)); |
| 38 | /// ``` |
| 39 | pub const MINrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MIN.: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] = Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](0); |
| 40 | |
| 41 | /// The largest value that can be represented by this integer type. |
| 42 | /// |
| 43 | /// # Examples |
| 44 | /// |
| 45 | /// Basic usage: |
| 46 | /// |
| 47 | /// ``` |
| 48 | /// # use {core::convert::TryFrom, js_int::UInt}; |
| 49 | /// assert_eq!(UInt::MAX, UInt::try_from(9_007_199_254_740_991u64).unwrap()); |
| 50 | /// ``` |
| 51 | pub const MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX.: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] = Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.); |
| 52 | |
| 53 | /// Try to create a `UInt` from the provided `u64`, returning `None` if it is larger than |
| 54 | /// `MAX_SAFE_UINT`. |
| 55 | /// |
| 56 | /// This is the same as the `TryFrom<u64>` implementation for `UInt`, except that it returns |
| 57 | /// an `Option` instead of a `Result`. |
| 58 | /// |
| 59 | /// # Examples |
| 60 | /// |
| 61 | /// Basic usage: |
| 62 | /// |
| 63 | /// ``` |
| 64 | /// # use js_int::UInt; |
| 65 | /// assert_eq!(UInt::new(js_int::MAX_SAFE_UINT), Some(UInt::MAX)); |
| 66 | /// assert_eq!(UInt::new(js_int::MAX_SAFE_UINT + 1), None); |
| 67 | /// ``` |
| 68 | #[must_use] |
| 69 | pub fn newrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new().(val: u64) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 70 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT. { |
| 71 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](val)) |
| 72 | } else { |
| 73 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /// Create a `UInt` from the provided `u64`, wrapping at `MAX_SAFE_UINT`. |
| 78 | /// |
| 79 | /// # Examples |
| 80 | /// |
| 81 | /// Basic usage: |
| 82 | /// |
| 83 | /// ``` |
| 84 | /// # use js_int::{uint, UInt}; |
| 85 | /// assert_eq!(UInt::new_wrapping(js_int::MAX_SAFE_UINT), UInt::MAX); |
| 86 | /// assert_eq!(UInt::new_wrapping(js_int::MAX_SAFE_UINT + 1), uint!(0)); |
| 87 | /// ``` |
| 88 | #[must_use] |
| 89 | pub fn new_wrappingrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_wrapping().(val: u64) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 90 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.) |
| 91 | } |
| 92 | |
| 93 | /// Creates an `UInt` from the given `u64` capped at `MAX_SAFE_UINT`. |
| 94 | /// |
| 95 | /// # Examples |
| 96 | /// |
| 97 | /// Basic usage: |
| 98 | /// |
| 99 | /// ``` |
| 100 | /// # use js_int::{uint, UInt}; |
| 101 | /// assert_eq!(UInt::new_saturating(0), uint!(0)); |
| 102 | /// assert_eq!(UInt::new_saturating(js_int::MAX_SAFE_UINT), UInt::MAX); |
| 103 | /// assert_eq!(UInt::new_saturating(js_int::MAX_SAFE_UINT + 1), UInt::MAX); |
| 104 | /// ``` |
| 105 | #[must_use] |
| 106 | pub fn new_saturatingrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_saturating().(val: u64) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 107 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT. { |
| 108 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](val) |
| 109 | } else { |
| 110 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX. |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /// The constructor used for arithmetic operations |
| 115 | #[must_use] |
| 116 | fn new_rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_().(val: u64) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 117 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(debug_assertions) { |
| 118 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(val <= MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.); |
| 119 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](val) |
| 120 | } else { |
| 121 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::new_wrappingrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_wrapping().(val) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /// Helper function for mutable arithmetic operations (`+=`, `-=`, …) |
| 126 | fn assign_rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]assign_().(&mut self, val: u64) { |
| 127 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(debug_assertions) { |
| 128 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(val <= MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.); |
| 129 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](val); |
| 130 | } else { |
| 131 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::new_wrappingrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_wrapping().(val); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /// Returns the smallest value that can be represented by this integer type. |
| 136 | /// |
| 137 | /// # Examples |
| 138 | /// |
| 139 | /// Basic usage: |
| 140 | /// |
| 141 | /// ``` |
| 142 | /// # use js_int::{uint, UInt}; |
| 143 | /// assert_eq!(UInt::min_value(), uint!(0)); |
| 144 | /// ``` |
| 145 | #[must_use] |
| 146 | #[deprecated = "Use `UInt::MIN` instead."] |
| 147 | pub const fn min_valuerust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]min_value().() -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 148 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](0) |
| 149 | } |
| 150 | |
| 151 | /// Returns the largest value that can be represented by this integer type. |
| 152 | /// |
| 153 | /// # Examples |
| 154 | /// |
| 155 | /// Basic usage: |
| 156 | /// |
| 157 | /// ``` |
| 158 | /// # use {core::convert::TryFrom, js_int::UInt}; |
| 159 | /// assert_eq!(UInt::max_value(), UInt::try_from(9_007_199_254_740_991u64).unwrap()); |
| 160 | /// ``` |
| 161 | #[must_use] |
| 162 | #[deprecated = "Use `UInt::MAX` instead."] |
| 163 | pub const fn max_valuerust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]max_value().() -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 164 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.) |
| 165 | } |
| 166 | |
| 167 | /// Returns true if and only if `self == 2^k` for some `k`. |
| 168 | /// |
| 169 | /// # Examples |
| 170 | /// |
| 171 | /// Basic usage: |
| 172 | /// |
| 173 | /// ``` |
| 174 | /// # use js_int::uint; |
| 175 | /// assert!(uint!(16).is_power_of_two()); |
| 176 | /// assert!(!uint!(10).is_power_of_two()); |
| 177 | /// ``` |
| 178 | #[must_use] |
| 179 | pub fn is_power_of_tworust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]is_power_of_two().(self) -> bool { |
| 180 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..is_power_of_tworust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]is_power_of_two().() |
| 181 | } |
| 182 | |
| 183 | /// Returns the smallest power of two greater than or equal to `n`. If the next power of two is |
| 184 | /// greater than the type's maximum value, `None` is returned, otherwise the power of two is |
| 185 | /// wrapped in `Some`. |
| 186 | /// |
| 187 | /// # Examples |
| 188 | /// |
| 189 | /// Basic usage: |
| 190 | /// |
| 191 | /// ``` |
| 192 | /// # use js_int::{uint, UInt}; |
| 193 | /// assert_eq!(uint!(2).checked_next_power_of_two(), Some(uint!(2))); |
| 194 | /// assert_eq!(uint!(3).checked_next_power_of_two(), Some(uint!(4))); |
| 195 | /// assert_eq!(UInt::MAX.checked_next_power_of_two(), None); |
| 196 | /// ``` |
| 197 | #[must_use] |
| 198 | pub fn checked_next_power_of_tworust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_next_power_of_two().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 199 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_next_power_of_tworust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_next_power_of_two().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::newrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new().) |
| 200 | } |
| 201 | |
| 202 | /// Converts a string slice in a given base to an integer. |
| 203 | /// |
| 204 | /// The string is expected to be an optional `+` sign followed by digits. Leading and trailing |
| 205 | /// whitespace represent an error. Digits are a subset of these characters, depending on |
| 206 | /// `radix`: |
| 207 | /// |
| 208 | /// * `0-9` |
| 209 | /// * `a-z` |
| 210 | /// * `A-Z` |
| 211 | /// |
| 212 | /// # Panics |
| 213 | /// |
| 214 | /// This function panics if `radix` is not in the range from 2 to 36. |
| 215 | /// |
| 216 | /// # Examples |
| 217 | /// |
| 218 | /// Basic usage: |
| 219 | /// |
| 220 | /// ``` |
| 221 | /// # use js_int::{uint, UInt}; |
| 222 | /// assert_eq!(UInt::from_str_radix("A", 16), Ok(uint!(10))); |
| 223 | /// ``` |
| 224 | pub fn from_str_radixrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]from_str_radix().(src: &str, radix: u32) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt], ParseIntErrorrust-analyzer cargo js_int 0.2.2 error/ParseIntError#> { |
| 225 | let val = u64::from_str_radixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]from_str_radix().(src, radix)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 226 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT. { |
| 227 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntErrorrust-analyzer cargo js_int 0.2.2 error/ParseIntError# { kindrust-analyzer cargo js_int 0.2.2 error/ParseIntError#kind.: ParseIntErrorKindrust-analyzer cargo js_int 0.2.2 error/ParseIntErrorKind#::Overflowrust-analyzer cargo js_int 0.2.2 error/ParseIntErrorKind#Overflow# }) |
| 228 | } else { |
| 229 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt](val)) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /// Checked integer addition. Computes `self + rhs`, returning `None` if overflow occurred. |
| 234 | /// |
| 235 | /// ``` |
| 236 | /// # use js_int::{uint, UInt}; |
| 237 | /// assert_eq!( |
| 238 | /// (UInt::MAX - uint!(2)).checked_add(uint!(1)), |
| 239 | /// Some(UInt::MAX - uint!(1)) |
| 240 | /// ); |
| 241 | /// assert_eq!((UInt::MAX - uint!(2)).checked_add(uint!(3)), None); |
| 242 | /// ``` |
| 243 | #[must_use] |
| 244 | pub fn checked_addrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_add().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 245 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_add().(rhs.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::newrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new().) |
| 246 | } |
| 247 | |
| 248 | /// Checked integer subtraction. Computes `self - rhs`, returning `None` if overflow occurred. |
| 249 | /// |
| 250 | /// # Examples |
| 251 | /// |
| 252 | /// Basic usage: |
| 253 | /// |
| 254 | /// ``` |
| 255 | /// # use js_int::uint; |
| 256 | /// assert_eq!(uint!(1).checked_sub(uint!(1)), Some(uint!(0))); |
| 257 | /// assert_eq!(uint!(0).checked_sub(uint!(1)), None); |
| 258 | /// ``` |
| 259 | #[must_use] |
| 260 | pub fn checked_subrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_sub().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 261 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_sub().(rhs.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::newrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new().) |
| 262 | } |
| 263 | |
| 264 | /// Checked integer multiplication. Computes `self * rhs`, returning `None` if overflow |
| 265 | /// occurred. |
| 266 | /// |
| 267 | /// # Examples |
| 268 | /// |
| 269 | /// Basic usage: |
| 270 | /// |
| 271 | /// ``` |
| 272 | /// # use js_int::{uint, UInt}; |
| 273 | /// assert_eq!(uint!(5).checked_mul(uint!(1)), Some(uint!(5))); |
| 274 | /// assert_eq!(UInt::MAX.checked_mul(uint!(2)), None); |
| 275 | /// ``` |
| 276 | #[must_use] |
| 277 | pub fn checked_mulrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_mul().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 278 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_mul().(rhs.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::newrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new().) |
| 279 | } |
| 280 | |
| 281 | /// Checked integer division. Computes `self / rhs`, returning `None` if `rhs == 0`. |
| 282 | /// |
| 283 | /// # Examples |
| 284 | /// |
| 285 | /// Basic usage: |
| 286 | /// |
| 287 | /// ``` |
| 288 | /// # use js_int::uint; |
| 289 | /// assert_eq!(uint!(128).checked_div(uint!(2)), Some(uint!(64))); |
| 290 | /// assert_eq!(uint!(1).checked_div(uint!(0)), None); |
| 291 | /// ``` |
| 292 | #[must_use] |
| 293 | pub fn checked_divrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_div().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 294 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_div().(rhs.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) |
| 295 | } |
| 296 | |
| 297 | /// Checked integer remainder. Computes `self % rhs`, returning `None` if `rhs == 0`. |
| 298 | /// |
| 299 | /// # Examples |
| 300 | /// |
| 301 | /// Basic usage: |
| 302 | /// |
| 303 | /// ``` |
| 304 | /// # use js_int::uint; |
| 305 | /// assert_eq!(uint!(5).checked_rem(uint!(2)), Some(uint!(1))); |
| 306 | /// assert_eq!(uint!(5).checked_rem(uint!(0)), None); |
| 307 | /// ``` |
| 308 | #[must_use] |
| 309 | pub fn checked_remrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_rem().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 310 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_remrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_rem().(rhs.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) |
| 311 | } |
| 312 | |
| 313 | /// Checked negation. Computes `-self`, returning None unless `self == 0`. |
| 314 | /// |
| 315 | /// Note that negating any positive integer will overflow. |
| 316 | /// |
| 317 | /// # Examples |
| 318 | /// |
| 319 | /// Basic usage: |
| 320 | /// |
| 321 | /// ``` |
| 322 | /// # use js_int::uint; |
| 323 | /// assert_eq!(uint!(0).checked_neg(), Some(uint!(0))); |
| 324 | /// assert_eq!(uint!(1).checked_neg(), None); |
| 325 | /// ``` |
| 326 | #[must_use] |
| 327 | pub fn checked_negrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_neg().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 328 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_negrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_neg().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) |
| 329 | } |
| 330 | |
| 331 | /// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if overflow or |
| 332 | /// underflow occurred. |
| 333 | /// |
| 334 | /// # Examples |
| 335 | /// |
| 336 | /// Basic usage: |
| 337 | /// |
| 338 | /// ``` |
| 339 | /// # use js_int::{uint, UInt}; |
| 340 | /// assert_eq!(uint!(0).checked_pow(2), Some(uint!(0))); |
| 341 | /// assert_eq!(uint!(8).checked_pow(2), Some(uint!(64))); |
| 342 | /// assert_eq!(uint!(1_000_000_000u32).checked_pow(2), None); |
| 343 | /// assert_eq!(UInt::MAX.checked_pow(2), None); |
| 344 | /// ``` |
| 345 | #[must_use] |
| 346 | pub fn checked_powrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_pow().(self, exp: u32) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]> { |
| 347 | self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..checked_powrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_pow().(exp).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::newrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new().) |
| 348 | } |
| 349 | |
| 350 | /// Saturating integer addition. Computes `self + rhs`, saturating at the numeric bounds |
| 351 | /// instead of overflowing. |
| 352 | /// |
| 353 | /// # Examples |
| 354 | /// |
| 355 | /// Basic usage: |
| 356 | /// |
| 357 | /// ``` |
| 358 | /// # use js_int::{uint, UInt}; |
| 359 | /// assert_eq!(uint!(100).saturating_add(uint!(1)), uint!(101)); |
| 360 | /// assert_eq!(UInt::MAX.saturating_add(uint!(1)), UInt::MAX); |
| 361 | /// ``` |
| 362 | #[must_use] |
| 363 | pub fn saturating_addrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]saturating_add().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 364 | self.checked_addrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_add().(rhs).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX.) |
| 365 | } |
| 366 | |
| 367 | /// Saturating integer subtraction. Computes `self - rhs`, saturating at the numeric |
| 368 | /// bounds instead of underflowing. |
| 369 | /// |
| 370 | /// # Examples |
| 371 | /// |
| 372 | /// Basic usage: |
| 373 | /// |
| 374 | /// ``` |
| 375 | /// # use js_int::uint; |
| 376 | /// assert_eq!(uint!(100).saturating_sub(uint!(1)), uint!(99)); |
| 377 | /// assert_eq!(uint!(1).saturating_sub(uint!(2)), uint!(0)); |
| 378 | /// ``` |
| 379 | #[must_use] |
| 380 | pub fn saturating_subrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]saturating_sub().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 381 | self.checked_subrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_sub().(rhs).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::MINrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MIN.) |
| 382 | } |
| 383 | |
| 384 | /// Saturating integer multiplication. Computes `self * rhs`, saturating at the numeric |
| 385 | /// bounds instead of overflowing. |
| 386 | /// |
| 387 | /// # Examples |
| 388 | /// |
| 389 | /// Basic usage: |
| 390 | /// |
| 391 | /// ``` |
| 392 | /// # use js_int::{uint, UInt}; |
| 393 | /// assert_eq!(uint!(100).saturating_mul(uint!(2)), uint!(200)); |
| 394 | /// assert_eq!(UInt::MAX.saturating_mul(uint!(2)), UInt::MAX); |
| 395 | /// assert_eq!(UInt::MAX.saturating_mul(UInt::MAX), UInt::MAX); |
| 396 | /// ``` |
| 397 | #[must_use] |
| 398 | pub fn saturating_mulrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]saturating_mul().(self, rhs: Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 399 | self.checked_mulrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]checked_mul().(rhs).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX.) |
| 400 | } |
| 401 | |
| 402 | /// Saturating integer exponentiation. Computes `self.pow(exp)`, saturating at the |
| 403 | /// numeric bounds instead of overflowing or underflowing. |
| 404 | /// |
| 405 | /// # Examples |
| 406 | /// |
| 407 | /// Basic usage: |
| 408 | /// |
| 409 | /// ``` |
| 410 | /// # use js_int::{uint, UInt}; |
| 411 | /// assert_eq!(uint!(5).saturating_pow(2), uint!(25)); |
| 412 | /// assert_eq!(UInt::MAX.saturating_pow(2), UInt::MAX); |
| 413 | /// ``` |
| 414 | #[must_use] |
| 415 | pub fn saturating_powrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]saturating_pow().(self, exp: u32) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt] { |
| 416 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]::new_saturatingrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_saturating().(self.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0..saturating_powrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_pow().(exp)) |
| 417 | } |
| 418 | |
| 419 | // TODO: wrapping_* methods, overflowing_* methods |
| 420 | } |
| 421 | |
| 422 | fmt_implsrust-analyzer cargo js_int 0.2.2 macros/fmt_impls!!(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#); |
| 423 | convert_implsrust-analyzer cargo js_int 0.2.2 macros/convert_impls!!(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#, u8, u16, u32, u64, u128, usize, i8, i16, i32, isize); |
| 424 | |
| 425 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<i8> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 426 | type Errorrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i8>`]Error# = TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#; |
| 427 | |
| 428 | fn try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i8>`]try_from().(val: i8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i8>`], TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#> { |
| 429 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge().0 { |
| 430 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i8>`](val as u64)) |
| 431 | } else { |
| 432 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#::newrust-analyzer cargo js_int 0.2.2 error/impl#[TryFromIntError]new().()) |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<i16> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 438 | type Errorrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i16>`]Error# = TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#; |
| 439 | |
| 440 | fn try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i16>`]try_from().(val: i16) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i16>`], TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#> { |
| 441 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().0 { |
| 442 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i16>`](val as u64)) |
| 443 | } else { |
| 444 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#::newrust-analyzer cargo js_int 0.2.2 error/impl#[TryFromIntError]new().()) |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<i32> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 450 | type Errorrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i32>`]Error# = TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#; |
| 451 | |
| 452 | fn try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i32>`]try_from().(val: i32) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i32>`], TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#> { |
| 453 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().0 { |
| 454 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i32>`](val as u64)) |
| 455 | } else { |
| 456 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#::newrust-analyzer cargo js_int 0.2.2 error/impl#[TryFromIntError]new().()) |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<i64> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 462 | type Errorrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i64>`]Error# = TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#; |
| 463 | |
| 464 | fn try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i64>`]try_from().(val: i64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i64>`], TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#> { |
| 465 | if (0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#MAX_SAFE_INTrust-analyzer cargo js_int 0.2.2 int/MAX_SAFE_INT.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&val) { |
| 466 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i64>`](val as u64)) |
| 467 | } else { |
| 468 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#::newrust-analyzer cargo js_int 0.2.2 error/impl#[TryFromIntError]new().()) |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<i128> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 474 | type Errorrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i128>`]Error# = TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#; |
| 475 | |
| 476 | fn try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i128>`]try_from().(val: i128) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i128>`], TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#> { |
| 477 | if (0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#MAX_SAFE_INTrust-analyzer cargo js_int 0.2.2 int/MAX_SAFE_INT..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&val) { |
| 478 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`TryFrom<i128>`](val as u64)) |
| 479 | } else { |
| 480 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TryFromIntErrorrust-analyzer cargo js_int 0.2.2 error/TryFromIntError#::newrust-analyzer cargo js_int 0.2.2 error/impl#[TryFromIntError]new().()) |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#> for i64 { |
| 486 | fn fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i64][`From<UInt>`]from().(val: UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[i64][`From<UInt>`] { |
| 487 | val.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0. as i64 |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#> for i128 { |
| 492 | fn fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i128][`From<UInt>`]from().(val: UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[i128][`From<UInt>`] { |
| 493 | val.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0. as i128 |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | macro_rules! uint_op_implrust-analyzer cargo js_int 0.2.2 uint/uint_op_impl! { |
| 498 | ($trait:ident, $method:ident, $assign_trait:ident, $assign_method:ident) => { |
| 499 | impl $trait for UInt { |
| 500 | type Output = Self; |
| 501 | |
| 502 | fn $method(self, rhs: Self) -> Self { |
| 503 | Self::new_(<u64 as $trait>::$method(self.0, rhs.0)) |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | impl $assign_trait for UInt { |
| 508 | fn $assign_method(&mut self, other: Self) { |
| 509 | self.assign_(<u64 as $trait>::$method(self.0, other.0)); |
| 510 | } |
| 511 | } |
| 512 | }; |
| 513 | } |
| 514 | |
| 515 | uint_op_implrust-analyzer cargo js_int 0.2.2 uint/uint_op_impl!!(Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#, addrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add()., AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#, add_assignrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`AddAssign<Self>`]add_assign().); |
| 516 | uint_op_implrust-analyzer cargo js_int 0.2.2 uint/uint_op_impl!!(Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#, subrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sub<Self>`]sub()., SubAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#, sub_assignrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`SubAssign<Self>`]sub_assign().); |
| 517 | uint_op_implrust-analyzer cargo js_int 0.2.2 uint/uint_op_impl!!(Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#, mulrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Mul<Self>`]mul()., MulAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/MulAssign#, mul_assignrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`MulAssign<Self>`]mul_assign().); |
| 518 | uint_op_implrust-analyzer cargo js_int 0.2.2 uint/uint_op_impl!!(Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#, divrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Div<Self>`]div()., DivAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/DivAssign#, div_assignrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`DivAssign<Self>`]div_assign().); |
| 519 | uint_op_implrust-analyzer cargo js_int 0.2.2 uint/uint_op_impl!!(Remrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Rem#, remrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Rem<Self>`]rem()., RemAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/RemAssign#, rem_assignrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`RemAssign<Self>`]rem_assign().); |
| 520 | |
| 521 | impl iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/accum/Sum# for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 522 | fn sumrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sum<Self>`]sum().<I>(iter: I) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sum<Self>`] |
| 523 | where |
| 524 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#>, |
| 525 | { |
| 526 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sum<Self>`]::new_rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_().(iter.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().()) |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | impl<'a> iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/accum/Sum#<&'a UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 531 | fn sumrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sum<&'a UInt>`]sum().<I>(iter: I) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sum<&'a UInt>`] |
| 532 | where |
| 533 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#>, |
| 534 | { |
| 535 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sum<&'a UInt>`]::new_rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_().(iter.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().()) |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | impl iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Productrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/accum/Product# for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 540 | fn productrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Product<Self>`]product().<I>(iter: I) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Product<Self>`] |
| 541 | where |
| 542 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#>, |
| 543 | { |
| 544 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Product<Self>`]::new_rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_().(iter.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).productrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#product().()) |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | impl<'a> iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Productrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/accum/Product#<&'a UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 549 | fn productrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Product<&'a UInt>`]product().<I>(iter: I) -> Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Product<&'a UInt>`] |
| 550 | where |
| 551 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'a UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#>, |
| 552 | { |
| 553 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Product<&'a UInt>`]::new_rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_().(iter.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| x.0rust-analyzer cargo js_int 0.2.2 uint/UInt#0.).productrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#product().()) |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 558 | type Errrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][FromStr]Err# = ParseIntErrorrust-analyzer cargo js_int 0.2.2 error/ParseIntError#; |
| 559 | |
| 560 | fn from_strrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][FromStr]from_str().(src: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][FromStr], Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 561 | let val = u64::from_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64][FromStr]from_str().(src)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 562 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT. { |
| 563 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseIntErrorrust-analyzer cargo js_int 0.2.2 error/ParseIntError# { kindrust-analyzer cargo js_int 0.2.2 error/ParseIntError#kind.: ParseIntErrorKindrust-analyzer cargo js_int 0.2.2 error/ParseIntErrorKind#::Overflowrust-analyzer cargo js_int 0.2.2 error/ParseIntErrorKind#Overflow# }) |
| 564 | } else { |
| 565 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][FromStr](val)) |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | #[cfg(feature = "serde")] |
| 571 | impl<'de> Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for UIntrust-analyzer cargo js_int 0.2.2 uint/UInt# { |
| 572 | fn deserializerust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> |
| 573 | where |
| 574 | D: Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>, |
| 575 | { |
| 576 | #[cfg(not(feature = "float_deserialize"))] |
| 577 | { |
| 578 | let val = u64::deserialize(deserializer)?; |
| 579 | |
| 580 | Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Deserialize<'de>`]::new(val).ok_or_else(|| { |
| 581 | D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#::invalid_value( |
| 582 | Unexpectedrust-analyzer cargo serde_core 1.0.229 de/Unexpected#::Unsignedrust-analyzer cargo serde_core 1.0.229 de/Unexpected#Unsigned#(val), |
| 583 | &"an integer between 0 and 2^53 - 1", |
| 584 | ) |
| 585 | }) |
| 586 | } |
| 587 | |
| 588 | #[cfg(feature = "float_deserialize")] |
| 589 | { |
| 590 | #[cfg(not(feature = "lax_deserialize"))] |
| 591 | const EXPECTING: &str = "a number between 0 and 2^53 - 1 without fractional component"; |
| 592 | #[cfg(feature = "lax_deserialize")] |
| 593 | const EXPECTINGrust-analyzer cargo js_int 0.2.2 uint/EXPECTING.: &str = "a number between 0 and 2^53 - 1"; |
| 594 | |
| 595 | let val = f64::deserializerust-analyzer cargo serde_core 1.0.229 de/impls/impl#[f64][`Deserialize<'de>`]deserialize().(deserializer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 596 | |
| 597 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]lt().0.0 || val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialOrd<Self>`]gt().MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT. as f64 || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().superrust-analyzer cargo js_int 0.2.2 crate/::is_acceptable_floatrust-analyzer cargo js_int 0.2.2 is_acceptable_float().(val) { |
| 598 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#::invalid_valuerust-analyzer cargo serde_core 1.0.229 de/Error#invalid_value().(Unexpectedrust-analyzer cargo serde_core 1.0.229 de/Unexpected#::Floatrust-analyzer cargo serde_core 1.0.229 de/Unexpected#Float#(val), &EXPECTINGrust-analyzer cargo js_int 0.2.2 uint/EXPECTING.)) |
| 599 | } else { |
| 600 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Deserialize<'de>`](val as u64)) |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | #[cfg(test)] |
| 607 | mod testsrust-analyzer cargo js_int 0.2.2 uint/tests/ { |
| 608 | use superrust-analyzer cargo js_int 0.2.2 uint/::{UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#, MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT.}; |
| 609 | |
| 610 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 611 | fn uint_opsrust-analyzer cargo js_int 0.2.2 uint/tests/uint_ops().() { |
| 612 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(5) +rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(8)); |
| 613 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(2) -rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sub<Self>`]sub(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1)); |
| 614 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(4) *rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Mul<Self>`]mul(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(2), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(8)); |
| 615 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(5) /rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Div<Self>`]div(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(2), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(2)); |
| 616 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(11) %rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Rem<Self>`]rem(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(4), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3)); |
| 617 | } |
| 618 | |
| 619 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 620 | fn uint_assign_opsrust-analyzer cargo js_int 0.2.2 uint/tests/uint_assign_ops().() { |
| 621 | let mut uint = uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1); |
| 622 | |
| 623 | uint rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`AddAssign<Self>`]add_assign(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`AddAssign<Self>`]add_assign().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3); |
| 624 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uint, uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(4)); |
| 625 | |
| 626 | uint rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`SubAssign<Self>`]sub_assign().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1); |
| 627 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uint, uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3)); |
| 628 | |
| 629 | uint rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`MulAssign<Self>`]mul_assign().*=rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`MulAssign<Self>`]mul_assign(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`MulAssign<Self>`]mul_assign().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3); |
| 630 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uint, uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(9)); |
| 631 | |
| 632 | uint rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`DivAssign<Self>`]div_assign(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`DivAssign<Self>`]div_assign().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3); |
| 633 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uint, uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(3)); |
| 634 | |
| 635 | uint rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`RemAssign<Self>`]rem_assign().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(2); |
| 636 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uint, uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1)); |
| 637 | } |
| 638 | |
| 639 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 640 | fn uint_wrapping_newrust-analyzer cargo js_int 0.2.2 uint/tests/uint_wrapping_new().() { |
| 641 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#::new_wrappingrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]new_wrapping().(MAX_SAFE_UINTrust-analyzer cargo js_int 0.2.2 uint/MAX_SAFE_UINT. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(0)); |
| 642 | } |
| 643 | |
| 644 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 645 | #[cfg_attr(debug_assertions, ignore)] |
| 646 | fn uint_underflow_wraprust-analyzer cargo js_int 0.2.2 uint/tests/uint_underflow_wrap().() { |
| 647 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(0) -rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sub<Self>`]sub(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1), UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX.); |
| 648 | } |
| 649 | |
| 650 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 651 | #[cfg_attr(debug_assertions, ignore)] |
| 652 | fn uint_overflow_wraprust-analyzer cargo js_int 0.2.2 uint/tests/uint_overflow_wrap().() { |
| 653 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX. +rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(0)); |
| 654 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX. +rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add(). uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(5), uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(4)); |
| 655 | } |
| 656 | |
| 657 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 658 | #[should_panic] |
| 659 | #[cfg_attr(not(debug_assertions), ignore)] |
| 660 | fn uint_underflow_panicrust-analyzer cargo js_int 0.2.2 uint/tests/uint_underflow_panic().() { |
| 661 | let _ = uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(0) rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sub<Self>`]sub().-rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sub<Self>`]sub(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Sub<Self>`]sub().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1); |
| 662 | } |
| 663 | |
| 664 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 665 | #[should_panic] |
| 666 | #[cfg_attr(not(debug_assertions), ignore)] |
| 667 | fn uint_overflow_panicrust-analyzer cargo js_int 0.2.2 uint/tests/uint_overflow_panic().() { |
| 668 | let _ = UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#::MAXrust-analyzer cargo js_int 0.2.2 uint/impl#[UInt]MAX. rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add().+rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add(). rust-analyzer cargo js_int 0.2.2 uint/impl#[UInt][`Add<Self>`]add().uintrust-analyzer cargo js_int 0.2.2 macros/uint!!(1); |
| 669 | } |
| 670 | |
| 671 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 672 | fn try_from_uint_for_i_nrust-analyzer cargo js_int 0.2.2 uint/tests/try_from_uint_for_i_n().() { |
| 673 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#; |
| 674 | let i8_max = i8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MAX. as u64; |
| 675 | let i16_max = i16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]MAX. as u64; |
| 676 | let i32_max = i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX. as u64; |
| 677 | |
| 678 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i8::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i8][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(0)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0)); |
| 679 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i8::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i8][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(10)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(10)); |
| 680 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i8::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i8][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i8_max)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(i8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MAX.)); |
| 681 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(i8::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i8][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i8_max +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 682 | |
| 683 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i16::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i16][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(0)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0)); |
| 684 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i16::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i16][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(10)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(10)); |
| 685 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i16::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i16][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i8_max +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((i8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MAX. as i16) +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). 1)); |
| 686 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i16::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i16][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i16_max)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(i16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]MAX.)); |
| 687 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(i16::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i16][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i16_max +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 688 | |
| 689 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i32::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i32][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(0)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0)); |
| 690 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i32::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i32][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(10)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(10)); |
| 691 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i32::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i32][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i16_max +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((i16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]MAX. as i32) +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). 1)); |
| 692 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i32::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i32][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i32_max)), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX.)); |
| 693 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(i32::try_fromrust-analyzer cargo js_int 0.2.2 uint/impl#[i32][`TryFrom<UInt>`]try_from().(UIntrust-analyzer cargo js_int 0.2.2 uint/UInt#(i32_max +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). 1)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 694 | } |
| 695 | } |