| 1 | //! Temporarily take ownership of a value at a mutable location, and replace it with a new value |
| 2 | //! based on the old one. |
| 3 | //! |
| 4 | //! <p style="font-family: 'Fira Sans',sans-serif;padding:0.3em 0"><strong> |
| 5 | //! <a href="https://crates.io/crates/replace_with">📦 Crates.io</a> │ <a href="https://github.com/alecmocatta/replace_with">📑 GitHub</a> │ <a href="https://constellation.zulipchat.com/#narrow/stream/213236-subprojects">💬 Chat</a> |
| 6 | //! </strong></p> |
| 7 | //! |
| 8 | //! This crate provides the function [`replace_with()`], which is like [`std::mem::replace()`] |
| 9 | //! except it allows the replacement value to be mapped from the original value. |
| 10 | //! |
| 11 | //! See [RFC 1736](https://github.com/rust-lang/rfcs/pull/1736) for a lot of discussion as to its |
| 12 | //! merits. It was never merged, and the desired ability to temporarily move out of `&mut T` doesn't |
| 13 | //! exist yet, so this crate is my interim solution. |
| 14 | //! |
| 15 | //! It's very akin to [`take_mut`](https://github.com/Sgeo/take_mut), though uses `Drop` instead of |
| 16 | //! [`std::panic::catch_unwind()`] to react to unwinding, which avoids the optimisation barrier of |
| 17 | //! calling the `extern "C" __rust_maybe_catch_panic()`. As such it's up to ∞x faster. The API also |
| 18 | //! attempts to make slightly more explicit the behavior on panic – [`replace_with()`] accepts two |
| 19 | //! closures such that aborting in the "standard case" where the mapping closure (`FnOnce(T) -> T`) |
| 20 | //! panics (as [`take_mut::take()`](https://docs.rs/take_mut/0.2.2/take_mut/fn.take.html) does) is |
| 21 | //! avoided. If the second closure (`FnOnce() -> T`) panics, however, then it does indeed abort. |
| 22 | //! The "abort on first panic" behaviour is available with [`replace_with_or_abort()`]. |
| 23 | //! |
| 24 | //! # Example |
| 25 | //! |
| 26 | //! Consider this motivating example: |
| 27 | //! |
| 28 | //! ```compile_fail |
| 29 | //! # use replace_with::*; |
| 30 | //! enum States { |
| 31 | //! A(String), |
| 32 | //! B(String), |
| 33 | //! } |
| 34 | //! |
| 35 | //! impl States { |
| 36 | //! fn poll(&mut self) { |
| 37 | //! // error[E0507]: cannot move out of borrowed content |
| 38 | //! *self = match *self { |
| 39 | //! // ^^^^^ cannot move out of borrowed content |
| 40 | //! States::A(a) => States::B(a), |
| 41 | //! States::B(a) => States::A(a), |
| 42 | //! }; |
| 43 | //! } |
| 44 | //! } |
| 45 | //! ``` |
| 46 | //! |
| 47 | //! Depending on context this can be quite tricky to work around. With this crate, however: |
| 48 | //! |
| 49 | //! ``` |
| 50 | //! # use replace_with::*; |
| 51 | //! enum States { |
| 52 | //! A(String), |
| 53 | //! B(String), |
| 54 | //! } |
| 55 | //! |
| 56 | //! # #[cfg(any(feature = "std", feature = "nightly"))] |
| 57 | //! impl States { |
| 58 | //! fn poll(&mut self) { |
| 59 | //! replace_with_or_abort(self, |self_| match self_ { |
| 60 | //! States::A(a) => States::B(a), |
| 61 | //! States::B(a) => States::A(a), |
| 62 | //! }); |
| 63 | //! } |
| 64 | //! } |
| 65 | //! ``` |
| 66 | //! |
| 67 | //! Huzzah! |
| 68 | //! |
| 69 | //! # `no_std` |
| 70 | //! |
| 71 | //! To use `replace_with` with `no_std` you have to disable the `std` feature, which is active by |
| 72 | //! default, by specifying your dependency to it like this: |
| 73 | //! |
| 74 | //! ```toml |
| 75 | //! # Cargo.toml |
| 76 | //! |
| 77 | //! replace_with = { version = "0.1", default-features = false } |
| 78 | //! ``` |
| 79 | //! |
| 80 | //! The `nightly` feature can be enabled to use [`core::intrinsics::abort()`](https://doc.rust-lang.org/core/intrinsics/fn.abort.html) |
| 81 | //! instead of triggering an abort via [`std::process::abort()`](https://doc.rust-lang.org/std/process/fn.abort.html) |
| 82 | //! or [`extern "C" fn abort() { panic!() } abort()`](https://doc.rust-lang.org/reference/items/functions.html#r-items.fn.extern.abort). |
| 83 | |
| 84 | #![cfg_attr(not(feature = "std"), no_std)] |
| 85 | #![cfg_attr(feature = "nightly", feature(core_intrinsics))] |
| 86 | #![doc(html_root_url = "https://docs.rs/replace_with/0.1.8")] |
| 87 | #![warn( |
| 88 | missing_copy_implementations, |
| 89 | missing_debug_implementations, |
| 90 | missing_docs, |
| 91 | trivial_casts, |
| 92 | trivial_numeric_casts, |
| 93 | unused_import_braces, |
| 94 | unused_qualifications, |
| 95 | unused_results, |
| 96 | // clippy::pedantic |
| 97 | )] |
| 98 | // #![allow(clippy::inline_always)] |
| 99 | |
| 100 | #[cfg(not(feature = "std"))] |
| 101 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/ as stdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/; |
| 102 | |
| 103 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/}; |
| 104 | |
| 105 | #[cfg(feature = "nightly")] |
| 106 | #[inline(always)] |
| 107 | fn abortrust-analyzer cargo replace_with 0.1.8 abort().() -> ! { |
| 108 | unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::intrinsicsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/::abortrust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/abort().() } |
| 109 | } |
| 110 | |
| 111 | #[cfg(all(not(feature = "nightly"), feature = "std"))] |
| 112 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::abortrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/abort().; |
| 113 | |
| 114 | // TODO: https://github.com/rust-lang/rfcs/issues/2512 |
| 115 | #[cfg(all(not(feature = "nightly"), not(feature = "std")))] |
| 116 | #[inline(always)] |
| 117 | fn abort() -> ! { |
| 118 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(panic = "abort") { |
| 119 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!() |
| 120 | } else { |
| 121 | // https://doc.rust-lang.org/reference/items/functions.html#r-items.fn.extern.abort |
| 122 | #[inline(always)] |
| 123 | extern "C" fn abort() -> ! { |
| 124 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 125 | } |
| 126 | on_unwindrust-analyzer cargo replace_with 0.1.8 on_unwind().(|| abortrust-analyzer cargo replace_with 0.1.8 abort().(), || loop {}) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // TODO: https://github.com/rust-lang/rust/issues/130338 |
| 131 | #[inline(always)] |
| 132 | fn abort_unwindrust-analyzer cargo replace_with 0.1.8 abort_unwind().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> R, R>(f: F) -> R { |
| 133 | on_unwindrust-analyzer cargo replace_with 0.1.8 on_unwind().(f, || abortrust-analyzer cargo replace_with 0.1.8 abort().()) |
| 134 | } |
| 135 | |
| 136 | struct OnDroprust-analyzer cargo replace_with 0.1.8 OnDrop#<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#()>(memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#<F>); |
| 137 | impl<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#()> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for OnDroprust-analyzer cargo replace_with 0.1.8 OnDrop#<F> { |
| 138 | #[inline(always)] |
| 139 | fn droprust-analyzer cargo replace_with 0.1.8 impl#[`OnDrop<F>`][Drop]drop().(&mut self) { |
| 140 | (unsafe { ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`][Deref]deref().self.0rust-analyzer cargo replace_with 0.1.8 OnDrop#0.) })(); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | #[inline(always)] |
| 145 | fn on_unwind_innerrust-analyzer cargo replace_with 0.1.8 on_unwind_inner().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T, T, P: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#()>(f: F, p: P) -> (T, P) { |
| 146 | if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(panic = "abort") { |
| 147 | return (f(), p); |
| 148 | } |
| 149 | let p = OnDroprust-analyzer cargo replace_with 0.1.8 OnDrop#(memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(p)); |
| 150 | let t = f(); |
| 151 | let mut p = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(p); |
| 152 | (t, unsafe { memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]take().(&mut p.0rust-analyzer cargo replace_with 0.1.8 OnDrop#0.) }) |
| 153 | } |
| 154 | |
| 155 | #[doc(hidden)] |
| 156 | #[inline(always)] |
| 157 | pub fn on_unwindrust-analyzer cargo replace_with 0.1.8 on_unwind().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T, T, P: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#()>(f: F, p: P) -> T { |
| 158 | on_unwind_innerrust-analyzer cargo replace_with 0.1.8 on_unwind_inner().(f, p).0 |
| 159 | } |
| 160 | |
| 161 | #[doc(hidden)] |
| 162 | #[inline(always)] |
| 163 | pub fn on_return_or_unwindrust-analyzer cargo replace_with 0.1.8 on_return_or_unwind().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T, T, P: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#()>(f: F, p: P) -> T { |
| 164 | let _p = OnDroprust-analyzer cargo replace_with 0.1.8 OnDrop#(memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::ManuallyDroprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/ManuallyDrop#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/manually_drop/impl#[`ManuallyDrop<T>`]new().(p)); |
| 165 | f() |
| 166 | } |
| 167 | |
| 168 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 169 | /// based on the old one. |
| 170 | /// |
| 171 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 172 | /// is then placed at the original value's location. |
| 173 | /// |
| 174 | /// # An important note |
| 175 | /// |
| 176 | /// On panic (or to be more precise, unwinding) of the closure `f`, `default` will be called to |
| 177 | /// provide a replacement value. `default` should not panic – doing so will abort the process. |
| 178 | /// |
| 179 | /// # Example |
| 180 | /// |
| 181 | /// ``` |
| 182 | /// # use replace_with::*; |
| 183 | /// enum States { |
| 184 | /// A(String), |
| 185 | /// B(String), |
| 186 | /// } |
| 187 | /// |
| 188 | /// impl States { |
| 189 | /// fn poll(&mut self) { |
| 190 | /// replace_with( |
| 191 | /// self, |
| 192 | /// || States::A(String::new()), |
| 193 | /// |self_| match self_ { |
| 194 | /// States::A(a) => States::B(a), |
| 195 | /// States::B(a) => States::A(a), |
| 196 | /// }, |
| 197 | /// ); |
| 198 | /// } |
| 199 | /// } |
| 200 | /// ``` |
| 201 | #[inline] |
| 202 | pub fn replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().<T, D: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> T>(dest: &mut T, default: D, f: F) { |
| 203 | unsafe { |
| 204 | let old = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(dest); |
| 205 | let (new, _default) = |
| 206 | on_unwind_innerrust-analyzer cargo replace_with 0.1.8 on_unwind_inner().(move || f(old), || ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(dest, abort_unwindrust-analyzer cargo replace_with 0.1.8 abort_unwind().(default))); |
| 207 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(dest, new); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 212 | /// based on the old one. Replaces with [`Default::default()`] on panic. |
| 213 | /// |
| 214 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 215 | /// is then placed at the original value's location. |
| 216 | /// |
| 217 | /// # An important note |
| 218 | /// |
| 219 | /// On panic (or to be more precise, unwinding) of the closure `f`, `T::default()` will be called to |
| 220 | /// provide a replacement value. `T::default()` should not panic – doing so will abort the process. |
| 221 | /// |
| 222 | /// Equivalent to `replace_with(dest, T::default, f)`. |
| 223 | /// |
| 224 | /// Differs from `*dest = mem::replace(dest, Default::default())` in that `Default::default()` will |
| 225 | /// only be called on panic. |
| 226 | /// |
| 227 | /// # Example |
| 228 | /// |
| 229 | /// ``` |
| 230 | /// # use replace_with::*; |
| 231 | /// enum States { |
| 232 | /// A(String), |
| 233 | /// B(String), |
| 234 | /// } |
| 235 | /// |
| 236 | /// impl Default for States { |
| 237 | /// fn default() -> Self { |
| 238 | /// States::A(String::new()) |
| 239 | /// } |
| 240 | /// } |
| 241 | /// |
| 242 | /// impl States { |
| 243 | /// fn poll(&mut self) { |
| 244 | /// replace_with_or_default(self, |self_| match self_ { |
| 245 | /// States::A(a) => States::B(a), |
| 246 | /// States::B(a) => States::A(a), |
| 247 | /// }); |
| 248 | /// } |
| 249 | /// } |
| 250 | /// ``` |
| 251 | #[inline] |
| 252 | pub fn replace_with_or_defaultrust-analyzer cargo replace_with 0.1.8 replace_with_or_default().<T: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> T>(dest: &mut T, f: F) { |
| 253 | replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().(dest, T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default()., f); |
| 254 | } |
| 255 | |
| 256 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 257 | /// based on the old one. Aborts on panic. |
| 258 | /// |
| 259 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 260 | /// is then placed at the original value's location. |
| 261 | /// |
| 262 | /// # An important note |
| 263 | /// |
| 264 | /// On panic (or to be more precise, unwinding) of the closure `f`, the process will **abort** to |
| 265 | /// avoid returning control while `dest` is in a potentially invalid state. |
| 266 | /// |
| 267 | /// If this behaviour is undesirable, use [`replace_with`] or [`replace_with_or_default`]. |
| 268 | /// |
| 269 | /// Equivalent to `replace_with(dest, || process::abort(), f)`. |
| 270 | /// |
| 271 | /// # Example |
| 272 | /// |
| 273 | /// ``` |
| 274 | /// # use replace_with::*; |
| 275 | /// enum States { |
| 276 | /// A(String), |
| 277 | /// B(String), |
| 278 | /// } |
| 279 | /// |
| 280 | /// # #[cfg(any(feature = "std", feature = "nightly"))] |
| 281 | /// impl States { |
| 282 | /// fn poll(&mut self) { |
| 283 | /// replace_with_or_abort(self, |self_| match self_ { |
| 284 | /// States::A(a) => States::B(a), |
| 285 | /// States::B(a) => States::A(a), |
| 286 | /// }); |
| 287 | /// } |
| 288 | /// } |
| 289 | /// ``` |
| 290 | #[inline] |
| 291 | pub fn replace_with_or_abortrust-analyzer cargo replace_with 0.1.8 replace_with_or_abort().<T, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> T>(dest: &mut T, f: F) { |
| 292 | replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().(dest, || abortrust-analyzer cargo replace_with 0.1.8 abort().(), f); |
| 293 | } |
| 294 | |
| 295 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 296 | /// based on the old one. Aborts on panic. |
| 297 | /// |
| 298 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 299 | /// is then placed at the original value's location. |
| 300 | /// |
| 301 | /// # An important note |
| 302 | /// |
| 303 | /// On panic (or to be more precise, unwinding) of the closure `f`, the process will **abort** to |
| 304 | /// avoid returning control while `dest` is in a potentially invalid state. |
| 305 | /// |
| 306 | /// Unlike for `replace_with_or_abort()` users of `replace_with_or_abort_unchecked()` are expected |
| 307 | /// to have `features = ["panic_abort", …]` defined in `Cargo.toml` |
| 308 | /// and `panic = "abort"` defined in their profile for it to behave semantically correct: |
| 309 | /// |
| 310 | /// ```toml |
| 311 | /// # Cargo.toml |
| 312 | /// |
| 313 | /// [profile.debug] |
| 314 | /// panic = "abort" |
| 315 | /// |
| 316 | /// [profile.release] |
| 317 | /// panic = "abort" |
| 318 | /// ``` |
| 319 | /// |
| 320 | /// # Safety |
| 321 | /// |
| 322 | /// It is crucial to only ever use this function having defined `panic = "abort"`, or else bad |
| 323 | /// things may happen. It's *up to you* to uphold this invariant! |
| 324 | /// |
| 325 | /// If this behaviour is undesirable, use [`replace_with`] or [`replace_with_or_default`]. |
| 326 | /// |
| 327 | /// Equivalent to `replace_with(dest, || process::abort(), f)`. |
| 328 | /// |
| 329 | /// # Example |
| 330 | /// |
| 331 | /// ``` |
| 332 | /// # use replace_with::*; |
| 333 | /// enum States { |
| 334 | /// A(String), |
| 335 | /// B(String), |
| 336 | /// } |
| 337 | /// |
| 338 | /// impl States { |
| 339 | /// fn poll(&mut self) { |
| 340 | /// unsafe { |
| 341 | /// replace_with_or_abort_unchecked(self, |self_| match self_ { |
| 342 | /// States::A(a) => States::B(a), |
| 343 | /// States::B(a) => States::A(a), |
| 344 | /// }); |
| 345 | /// } |
| 346 | /// } |
| 347 | /// } |
| 348 | /// ``` |
| 349 | /// |
| 350 | #[inline] |
| 351 | #[cfg(feature = "panic_abort")] |
| 352 | #[deprecated = "Use replace_with_or_abort() instead, which used cfg!(panic = \"abort\") to guarentee soundness"] |
| 353 | pub unsafe fn replace_with_or_abort_uncheckedrust-analyzer cargo replace_with 0.1.8 replace_with_or_abort_unchecked().<T, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> T>(dest: &mut T, f: F) { |
| 354 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(dest, f(ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(dest))); |
| 355 | } |
| 356 | |
| 357 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 358 | /// based on the old one. Lets the closure return a custom value as well. |
| 359 | /// |
| 360 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 361 | /// is then placed at the original value's location. |
| 362 | /// |
| 363 | /// This is effectively the same function as [`replace_with`], but it lets the closure return a |
| 364 | /// custom value as well. |
| 365 | /// |
| 366 | /// # An important note |
| 367 | /// |
| 368 | /// On panic (or to be more precise, unwinding) of the closure `f`, `default` will be called to |
| 369 | /// provide a replacement value. `default` should not panic – doing so will abort the process. |
| 370 | /// |
| 371 | /// # Example |
| 372 | /// |
| 373 | /// ``` |
| 374 | /// # use replace_with::*; |
| 375 | /// |
| 376 | /// fn take<T>(option: &mut Option<T>) -> Option<T> { |
| 377 | /// replace_with_and_return(option, || None, |option| (option, None)) |
| 378 | /// } |
| 379 | /// |
| 380 | /// let mut opt = Some(3); |
| 381 | /// assert_eq!(take(&mut opt), Some(3)); |
| 382 | /// assert_eq!(take(&mut opt), None); |
| 383 | /// ``` |
| 384 | #[inline] |
| 385 | pub fn replace_with_and_returnrust-analyzer cargo replace_with 0.1.8 replace_with_and_return().<T, U, D: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> (U, T)>( |
| 386 | dest: &mut T, default: D, f: F, |
| 387 | ) -> U { |
| 388 | unsafe { |
| 389 | let old = ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(dest); |
| 390 | let ((res, new), _default) = |
| 391 | on_unwind_innerrust-analyzer cargo replace_with 0.1.8 on_unwind_inner().(move || f(old), || ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(dest, abort_unwindrust-analyzer cargo replace_with 0.1.8 abort_unwind().(default))); |
| 392 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(dest, new); |
| 393 | res |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 398 | /// based on the old one. Replaces with [`Default::default()`] on panic. |
| 399 | /// Lets the closure return a custom value as well. |
| 400 | /// |
| 401 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 402 | /// is then placed at the original value's location. |
| 403 | /// |
| 404 | /// This is effectively the same function as [`replace_with_or_default`], but it lets the closure |
| 405 | /// return a custom value as well. |
| 406 | /// |
| 407 | /// # An important note |
| 408 | /// |
| 409 | /// On panic (or to be more precise, unwinding) of the closure `f`, `T::default()` will be called to |
| 410 | /// provide a replacement value. `T::default()` should not panic – doing so will abort the process. |
| 411 | /// |
| 412 | /// Equivalent to `replace_with_and_return(dest, T::default, f)`. |
| 413 | /// |
| 414 | /// # Example |
| 415 | /// |
| 416 | /// ``` |
| 417 | /// # use replace_with::*; |
| 418 | /// |
| 419 | /// fn take<T>(option: &mut Option<T>) -> Option<T> { |
| 420 | /// replace_with_or_default_and_return(option, |option| (option, None)) |
| 421 | /// } |
| 422 | /// ``` |
| 423 | #[inline] |
| 424 | pub fn replace_with_or_default_and_returnrust-analyzer cargo replace_with 0.1.8 replace_with_or_default_and_return().<T: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, U, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> (U, T)>( |
| 425 | dest: &mut T, f: F, |
| 426 | ) -> U { |
| 427 | replace_with_and_returnrust-analyzer cargo replace_with 0.1.8 replace_with_and_return().(dest, T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default()., f) |
| 428 | } |
| 429 | |
| 430 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 431 | /// based on the old one. Aborts on panic. Lets the closure return a custom value as well. |
| 432 | /// |
| 433 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 434 | /// is then placed at the original value's location. |
| 435 | /// |
| 436 | /// This is effectively the same function as [`replace_with_or_abort`], but it lets the closure |
| 437 | /// return a custom value as well. |
| 438 | /// |
| 439 | /// # An important note |
| 440 | /// |
| 441 | /// On panic (or to be more precise, unwinding) of the closure `f`, the process will **abort** to |
| 442 | /// avoid returning control while `dest` is in a potentially invalid state. |
| 443 | /// |
| 444 | /// If this behaviour is undesirable, use [`replace_with_and_return`] or |
| 445 | /// [`replace_with_or_default_and_return`] instead. |
| 446 | /// |
| 447 | /// Equivalent to `replace_with_and_return(dest, || process::abort(), f)`. |
| 448 | /// |
| 449 | /// # Example |
| 450 | /// |
| 451 | /// ``` |
| 452 | /// # use replace_with::*; |
| 453 | /// |
| 454 | /// fn take<T>(option: &mut Option<T>) -> Option<T> { |
| 455 | /// replace_with_or_abort_and_return(option, |option| (option, None)) |
| 456 | /// } |
| 457 | /// ``` |
| 458 | #[inline] |
| 459 | pub fn replace_with_or_abort_and_returnrust-analyzer cargo replace_with 0.1.8 replace_with_or_abort_and_return().<T, U, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> (U, T)>(dest: &mut T, f: F) -> U { |
| 460 | replace_with_and_returnrust-analyzer cargo replace_with 0.1.8 replace_with_and_return().(dest, || abortrust-analyzer cargo replace_with 0.1.8 abort().(), f) |
| 461 | } |
| 462 | |
| 463 | /// Temporarily takes ownership of a value at a mutable location, and replace it with a new value |
| 464 | /// based on the old one. Aborts on panic. Lets the closure return a custom value as well. |
| 465 | /// |
| 466 | /// We move out of the reference temporarily, to apply a closure `f`, returning a new value, which |
| 467 | /// is then placed at the original value's location. |
| 468 | /// |
| 469 | /// This is effectively the same function as [`replace_with_or_abort_unchecked`], but it lets the |
| 470 | /// closure return a custom value as well. |
| 471 | /// |
| 472 | /// # An important note |
| 473 | /// |
| 474 | /// On panic (or to be more precise, unwinding) of the closure `f`, the process will **abort** to |
| 475 | /// avoid returning control while `dest` is in a potentially invalid state. |
| 476 | /// |
| 477 | /// Unlike for `replace_with_or_abort()` users of `replace_with_or_abort_unchecked()` are expected |
| 478 | /// to have `features = ["panic_abort", …]` defined in `Cargo.toml` |
| 479 | /// and `panic = "abort"` defined in their profile for it to behave semantically correct: |
| 480 | /// |
| 481 | /// ```toml |
| 482 | /// # Cargo.toml |
| 483 | /// |
| 484 | /// [profile.debug] |
| 485 | /// panic = "abort" |
| 486 | /// |
| 487 | /// [profile.release] |
| 488 | /// panic = "abort" |
| 489 | /// ``` |
| 490 | /// |
| 491 | /// # Safety |
| 492 | /// |
| 493 | /// It is crucial to only ever use this function having defined `panic = "abort"`, or else bad |
| 494 | /// things may happen. It's *up to you* to uphold this invariant! |
| 495 | /// |
| 496 | /// If this behaviour is undesirable, use [`replace_with_and_return`] or |
| 497 | /// [`replace_with_or_default_and_return`]. |
| 498 | /// |
| 499 | /// Equivalent to `replace_with_and_return(dest, || process::abort(), f)`. |
| 500 | /// |
| 501 | /// # Example |
| 502 | /// |
| 503 | /// ``` |
| 504 | /// # use replace_with::*; |
| 505 | /// |
| 506 | /// unsafe fn take<T>(option: &mut Option<T>) -> Option<T> { |
| 507 | /// replace_with_or_abort_and_return_unchecked(option, |option| (option, None)) |
| 508 | /// } |
| 509 | /// ``` |
| 510 | #[inline] |
| 511 | #[cfg(feature = "panic_abort")] |
| 512 | #[deprecated = "Use replace_with_or_abort_and_return() instead, which used cfg!(panic = \"abort\") to guarentee soundness"] |
| 513 | pub unsafe fn replace_with_or_abort_and_return_uncheckedrust-analyzer cargo replace_with 0.1.8 replace_with_or_abort_and_return_unchecked().<T, U, F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> (U, T)>( |
| 514 | dest: &mut T, f: F, |
| 515 | ) -> U { |
| 516 | let (res, new) = f(ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(dest)); |
| 517 | ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(dest, new); |
| 518 | res |
| 519 | } |
| 520 | |
| 521 | #[cfg(test)] |
| 522 | mod testrust-analyzer cargo replace_with 0.1.8 test/ { |
| 523 | /// https://github.com/alecmocatta/replace_with/issues/18 replace_with[_and_return] has |
| 524 | /// undefined behavior if default panics. |
| 525 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 526 | #[ignore = "should abort, cc https://github.com/rust-lang/rust/issues/67650"] |
| 527 | #[cfg(feature = "std")] |
| 528 | fn default_panicrust-analyzer cargo replace_with 0.1.8 test/default_panic().() { |
| 529 | let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("abc"); |
| 530 | replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().( |
| 531 | &mut s, |
| 532 | move || { |
| 533 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 534 | }, |
| 535 | |s| { |
| 536 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(s); |
| 537 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 538 | }, |
| 539 | ); |
| 540 | } |
| 541 | |
| 542 | /// https://github.com/alecmocatta/replace_with/issues/21 replace_with doesn't write the return |
| 543 | /// value before dropping the default closure, causing a use after free if the drop glue of the |
| 544 | /// latter panics |
| 545 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 546 | #[should_panic] |
| 547 | #[cfg(feature = "std")] |
| 548 | fn default_drop_panicrust-analyzer cargo replace_with 0.1.8 test/default_drop_panic().() { |
| 549 | struct OnDropPanicrust-analyzer cargo replace_with 0.1.8 test/OnDropPanic#(); |
| 550 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for OnDropPanicrust-analyzer cargo replace_with 0.1.8 test/OnDropPanic# { |
| 551 | fn droprust-analyzer cargo replace_with 0.1.8 test/impl#[OnDropPanic][Drop]drop().(&mut self) { |
| 552 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("abc"); |
| 557 | let panicking_drop = OnDropPanicrust-analyzer cargo replace_with 0.1.8 test/OnDropPanic#(); |
| 558 | replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().( |
| 559 | &mut s, |
| 560 | // The code inside this closure never runs, but because `panicking_drop` is owned by the |
| 561 | // closure, dropping this closure causes a panic. |
| 562 | move || { |
| 563 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(panicking_drop); |
| 564 | unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!() |
| 565 | }, |
| 566 | |s| { |
| 567 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(s); |
| 568 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().() |
| 569 | }, |
| 570 | ); |
| 571 | } |
| 572 | |
| 573 | // These functions copied from https://github.com/Sgeo/take_mut/blob/1bd70d842c6febcd16ec1fe3a954a84032b89f52/src/lib.rs#L102-L147 |
| 574 | |
| 575 | // Copyright (c) 2016 Sgeo |
| 576 | |
| 577 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 578 | // of this software and associated documentation files (the "Software"), to deal |
| 579 | // in the Software without restriction, including without limitation the rights |
| 580 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 581 | // copies of the Software, and to permit persons to whom the Software is |
| 582 | // furnished to do so, subject to the following conditions: |
| 583 | |
| 584 | // The above copyright notice and this permission notice shall be included in all |
| 585 | // copies or substantial portions of the Software. |
| 586 | |
| 587 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 588 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 589 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 590 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 591 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 592 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 593 | // SOFTWARE. |
| 594 | |
| 595 | use superrust-analyzer cargo replace_with 0.1.8 crate/::*; |
| 596 | |
| 597 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 598 | fn it_works_recoverrust-analyzer cargo replace_with 0.1.8 test/it_works_recover().() { |
| 599 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 600 | enum Foorust-analyzer cargo replace_with 0.1.8 test/Foo# { |
| 601 | Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#, |
| 602 | Brust-analyzer cargo replace_with 0.1.8 test/Foo#B#, |
| 603 | } |
| 604 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Foorust-analyzer cargo replace_with 0.1.8 test/Foo# { |
| 605 | #[cfg(feature = "std")] |
| 606 | fn droprust-analyzer cargo replace_with 0.1.8 test/impl#[Foo][Drop]drop().(&mut self) { |
| 607 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 608 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A# => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Foo::A dropped"), |
| 609 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B# => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Foo::B dropped"), |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | #[cfg(not(feature = "std"))] |
| 614 | fn drop(&mut self) { |
| 615 | match *selfrust-analyzer cargo replace_with 0.1.8 test/ { |
| 616 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A# | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B# => (), |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | let mut quax = Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#; |
| 621 | replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().( |
| 622 | &mut quax, |
| 623 | || Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#, |
| 624 | |f| { |
| 625 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(f); |
| 626 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B# |
| 627 | }, |
| 628 | ); |
| 629 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&quax, &Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B#); |
| 630 | |
| 631 | let n = replace_with_and_returnrust-analyzer cargo replace_with 0.1.8 replace_with_and_return().( |
| 632 | &mut quax, |
| 633 | || Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B#, |
| 634 | |f| { |
| 635 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(f); |
| 636 | (3, Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#) |
| 637 | }, |
| 638 | ); |
| 639 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(n, 3); |
| 640 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&quax, &Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#); |
| 641 | } |
| 642 | |
| 643 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 644 | #[cfg(feature = "std")] |
| 645 | fn it_works_recover_panicrust-analyzer cargo replace_with 0.1.8 test/it_works_recover_panic().() { |
| 646 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/; |
| 647 | |
| 648 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 649 | enum Foorust-analyzer cargo replace_with 0.1.8 test/Foo# { |
| 650 | Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#, |
| 651 | Brust-analyzer cargo replace_with 0.1.8 test/Foo#B#, |
| 652 | Crust-analyzer cargo replace_with 0.1.8 test/Foo#C#, |
| 653 | } |
| 654 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Foorust-analyzer cargo replace_with 0.1.8 test/Foo# { |
| 655 | fn droprust-analyzer cargo replace_with 0.1.8 test/impl#[Foo][Drop]drop().(&mut self) { |
| 656 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 657 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A# => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Foo::A dropped"), |
| 658 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B# => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Foo::B dropped"), |
| 659 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Crust-analyzer cargo replace_with 0.1.8 test/Foo#C# => printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Foo::C dropped"), |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | let mut quax = Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Arust-analyzer cargo replace_with 0.1.8 test/Foo#A#; |
| 664 | |
| 665 | let res = panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::catch_unwindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/catch_unwind().(panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::AssertUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/AssertUnwindSafe#(|| { |
| 666 | replace_withrust-analyzer cargo replace_with 0.1.8 replace_with().( |
| 667 | &mut quax, |
| 668 | || Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Crust-analyzer cargo replace_with 0.1.8 test/Foo#C#, |
| 669 | |f| { |
| 670 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(f); |
| 671 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("panic"); |
| 672 | #[allow(unreachable_code)] |
| 673 | Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Brust-analyzer cargo replace_with 0.1.8 test/Foo#B# |
| 674 | }, |
| 675 | ); |
| 676 | })); |
| 677 | |
| 678 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 679 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&quax, &Foorust-analyzer cargo replace_with 0.1.8 test/Foo#::Crust-analyzer cargo replace_with 0.1.8 test/Foo#C#); |
| 680 | } |
| 681 | } |