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