error.rs
This file
Path
src/error.rs
426 lines · 11.5 KiB · Rust
Last changed by
Add Error::root_cause accessorDavid Tolnaybefore adoption1ea72bb
History of this fileTake it
Add context method to ErrorDavid Tolnaybefore adoption41fde4c
line 1why, one step back1use crate::context::ContextError;Rename exception module to errorDavid Tolnaybefore adoption2000930
line 2why, one step back2use std::any::TypeId;Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 3why, one step back3use std::error::Error as StdError;Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 4–8why, one step back4use std::fmt::{self, Debug, Display};5use std::mem;6use std::ops::{Deref, DerefMut};7use std::ptr;8Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e
lines 9–11why, one step back9#[cfg(backtrace)]10use std::backtrace::{Backtrace, BacktraceStatus};11Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 12why, one step back12/// The `Error` type, a wrapper around a dynamic error type.Rename exception module to errorDavid Tolnaybefore adoption2000930
line 13why, one step back13///Touch up documentation on Error structDavid Tolnaybefore adoptiona8ce6e4
line 14why, one step back14/// `Error` works a lot like `Box<dyn std::error::Error>`, but with theseWrap comments to 80 columnsDavid Tolnaybefore adoption9745066
line 15why, one step back15/// differences:Rename exception module to errorDavid Tolnaybefore adoption2000930
line 16why, one step back16///Touch up documentation on Error structDavid Tolnaybefore adoptiona8ce6e4
lines 17–21why, one step back17/// - `Error` requires that the error is `Send`, `Sync`, and `'static`.18/// - `Error` guarantees that a backtrace is available, even if the underlying19/// error type does not provide one.20/// - `Error` is represented as a narrow pointer — exactly one word in21/// size instead of two.Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 22why, one step back22pub struct Error {Rename InnerException to ErrorImplDavid Tolnaybefore adoption68dcc84
line 23why, one step back23 inner: Box<ErrorImpl<()>>,Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 24–25why, one step back24}25Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 26why, one step back26impl Error {Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 27why, one step back27 /// Create a new error object from any error type.Rename exception module to errorDavid Tolnaybefore adoption2000930
line 28why, one step back28 ///Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066
lines 29–30why, one step back29 /// The error type must be threadsafe and `'static`, so that the `Error`30 /// will be as well.Rename exception module to errorDavid Tolnaybefore adoption2000930
line 31why, one step back31 ///Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066
lines 32–33why, one step back32 /// If the error type does not provide a backtrace, a backtrace will be33 /// created here to ensure that a backtrace exists.Use Self in signatures of Error constructorsDavid Tolnaybefore adoption1ee4337
line 34why, one step back34 pub fn new<E>(error: E) -> SelfRename exception module to errorDavid Tolnaybefore adoption2000930
line 35why, one step back35 whereImport std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 36why, one step back36 E: StdError + Send + Sync + 'static,Rename exception module to errorDavid Tolnaybefore adoption2000930
line 37why, one step back37 {Remove a layer of wrapping from debug mode backtracesDavid Tolnaybefore adoption97314ac
lines 38–45why, one step back38 // Captured here instead of in Error::construct to have one fewer layer39 // of wrapping visible in the backtrace.40 #[cfg(backtrace)]41 let backtrace = match error.backtrace() {42 Some(_) => None,43 None => Some(Backtrace::capture()),44 };45Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f
lines 46–49why, one step back46 #[cfg(not(backtrace))]47 let backtrace = None;4849 Error::construct(error, TypeId::of::<E>(), backtrace)Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 50–51why, one step back50 }51Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f
line 52why, one step back52 pub(crate) fn new_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> SelfRename exception module to errorDavid Tolnaybefore adoption2000930
lines 53–55why, one step back53 where54 M: Display + Debug + Send + Sync + 'static,55 {Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f
line 56why, one step back56 Error::construct(MessageError(message), TypeId::of::<M>(), backtrace)Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 57–58why, one step back57 }58Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f
line 59why, one step back59 fn construct<E>(error: E, type_id: TypeId, backtrace: Option<Backtrace>) -> SelfRename exception module to errorDavid Tolnaybefore adoption2000930
line 60why, one step back60 whereImport std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 61why, one step back61 E: StdError + Send + Sync + 'static,Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 62–63why, one step back62 {63 unsafe {Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742
lines 64–65why, one step back64 let obj = mem::transmute::<&dyn StdError, TraitObject>(&error);65 let inner = Box::new(ErrorImpl {Remove a layer of wrapping from debug mode backtracesDavid Tolnaybefore adoption97314ac
line 66why, one step back66 vtable: obj.vtable,Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 67–69why, one step back67 type_id,68 backtrace,69 error,Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742
line 70why, one step back70 });Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 71why, one step back71 Error {Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742
line 72why, one step back72 inner: mem::transmute::<Box<ErrorImpl<E>>, Box<ErrorImpl<()>>>(inner),Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 73–74why, one step back73 }74 }Add context method to ErrorDavid Tolnaybefore adoption41fde4c
lines 75–77why, one step back75 }7677 /// Wrap the error value with additional context.Link to Context trait from Error::context methodDavid Tolnaybefore adoption61e587f
lines 78–81why, one step back78 ///79 /// For attaching context to a `Result` as it is propagated, the80 /// [`Context`][crate::Context] extension trait may be more convenient than81 /// this function.Add context method to ErrorDavid Tolnaybefore adoption41fde4c
lines 82–89why, one step back82 pub fn context<C>(self, context: C) -> Self83 where84 C: Display + Send + Sync + 'static,85 {86 Error::from(ContextError {87 error: self,88 context,89 })Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 90–91why, one step back90 }91Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 92why, one step back92 /// Get the backtrace for this Error.Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e
lines 93–96why, one step back93 ///94 /// Backtraces are only available on the nightly channel. Tracking issue:95 /// [rust-lang/rust#53487][tracking].96 ///Mention env var in Error::backtrace documentationDavid Tolnaybefore adoption4119806
lines 97–101why, one step back97 /// In order for the backtrace to be meaningful, the environment variable98 /// `RUST_LIB_BACKTRACE=1` must be defined. Backtraces are somewhat99 /// expensive to capture in Rust, so we don't necessarily want to be100 /// capturing them all over the place all the time.101 ///Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e
lines 102–103why, one step back102 /// [tracking]: https://github.com/rust-lang/rust/issues/53487103 #[cfg(backtrace)]Rename exception module to errorDavid Tolnaybefore adoption2000930
line 104why, one step back104 pub fn backtrace(&self) -> &Backtrace {Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066
lines 105–107why, one step back105 // NB: this unwrap can only fail if the underlying error's backtrace106 // method is nondeterministic, which would only happen in maliciously107 // constructed codeRename exception module to errorDavid Tolnaybefore adoption2000930
lines 108–111why, one step back108 self.inner109 .backtrace110 .as_ref()111 .or_else(|| self.inner.error().backtrace())Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 112why, one step back112 .expect("backtrace capture failed")Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 113–114why, one step back113 }114Rename Errors to ChainDavid Tolnaybefore adoptionf972193
line 115why, one step back115 /// An iterator of the chain of source errors contained by this Error.Rename exception module to errorDavid Tolnaybefore adoption2000930
line 116why, one step back116 ///Rename Errors to ChainDavid Tolnaybefore adoptionf972193
line 117why, one step back117 /// This iterator will visit every error in the cause chain of this errorWrap comments to 80 columnsDavid Tolnaybefore adoption9745066
lines 118–119why, one step back118 /// object, beginning with the error that this error object was created119 /// from.Rename Errors to ChainDavid Tolnaybefore adoptionf972193
lines 120–121why, one step back120 pub fn chain(&self) -> Chain {121 Chain {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 122–125why, one step back122 next: Some(self.inner.error()),123 }124 }125Add Error::root_cause accessorDavid Tolnaybefore adoption1ea72bb
lines 126–139why, one step back126 /// The lowest level cause of this error — this error's cause's127 /// cause's cause etc.128 ///129 /// The root cause is the last error in the iterator produced by130 /// [`chain()`][Error::chain].131 pub fn root_cause(&self) -> &(dyn StdError + 'static) {132 let mut chain = self.chain();133 let mut root_cause = chain.next().unwrap();134 for cause in chain {135 root_cause = cause;136 }137 root_cause138 }139Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 140why, one step back140 /// Returns `true` if `E` is the type wrapped by this error object.Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 141–144why, one step back141 pub fn is<E>(&self) -> bool142 where143 E: Display + Debug + Send + Sync + 'static,144 {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 145–147why, one step back145 TypeId::of::<E>() == self.inner.type_id146 }147Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 148why, one step back148 /// Attempt to downcast the error object to a concrete type.Use Self in signatures of Error constructorsDavid Tolnaybefore adoption1ee4337
line 149why, one step back149 pub fn downcast<E>(self) -> Result<E, Self>Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 150–152why, one step back150 where151 E: Display + Debug + Send + Sync + 'static,152 {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 153–164why, one step back153 if let Some(error) = self.downcast_ref::<E>() {154 unsafe {155 let error = ptr::read(error);156 drop(ptr::read(&self.inner));157 mem::forget(self);158 Ok(error)159 }160 } else {161 Err(self)162 }163 }164Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 165why, one step back165 /// Downcast this error object by reference.Add example to Error::downcast_refDavid Tolnaybefore adoption0c21b7a
lines 166–200why, one step back166 ///167 /// # Example168 ///169 /// ```170 /// # use anyhow::anyhow;171 /// # use std::fmt::{self, Display};172 /// # use std::task::Poll;173 /// #174 /// # #[derive(Debug)]175 /// # enum DataStoreError {176 /// # Censored(()),177 /// # }178 /// #179 /// # impl Display for DataStoreError {180 /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {181 /// # unimplemented!()182 /// # }183 /// # }184 /// #185 /// # impl std::error::Error for DataStoreError {}186 /// #187 /// # const REDACTED_CONTENT: () = ();188 /// #189 /// # let error = anyhow!("...");190 /// # let root_cause = &error;191 /// #192 /// # let ret =193 /// // If the error was caused by redaction, then return a tombstone instead194 /// // of the content.195 /// match root_cause.downcast_ref::<DataStoreError>() {196 /// Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),197 /// None => Err(error),198 /// }199 /// # ;200 /// ```Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 201–204why, one step back201 pub fn downcast_ref<E>(&self) -> Option<&E>202 where203 E: Display + Debug + Send + Sync + 'static,204 {Rename exception module to errorDavid Tolnaybefore adoption2000930
line 205why, one step back205 if self.is::<E>() {Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 206why, one step back206 unsafe { Some(&*(self.inner.error() as *const dyn StdError as *const E)) }Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 207–211why, one step back207 } else {208 None209 }210 }211Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 212why, one step back212 /// Downcast this error object by mutable reference.Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 213–216why, one step back213 pub fn downcast_mut<E>(&mut self) -> Option<&mut E>214 where215 E: Display + Debug + Send + Sync + 'static,216 {Rename exception module to errorDavid Tolnaybefore adoption2000930
line 217why, one step back217 if self.is::<E>() {Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 218why, one step back218 unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn StdError as *mut E)) }Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 219–223why, one step back219 } else {220 None221 }222 }223}Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f
lines 224–226why, one step back224225#[cfg(not(backtrace))]226pub(crate) enum Backtrace {}Rename exception module to errorDavid Tolnaybefore adoption2000930
line 227why, one step back227Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 228–231why, one step back228impl<E> From<E> for Error229where230 E: StdError + Send + Sync + 'static,231{Use Self in signatures of Error constructorsDavid Tolnaybefore adoption1ee4337
line 232why, one step back232 fn from(error: E) -> Self {Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 233why, one step back233 Error::new(error)Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 234–236why, one step back234 }235}236Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 237why, one step back237impl Deref for Error {Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 238why, one step back238 type Target = dyn StdError + Send + Sync + 'static;Remove as_dyn_error methods from ErrorDavid Tolnaybefore adoption73c7283
line 239why, one step back239Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 240–244why, one step back240 fn deref(&self) -> &Self::Target {241 self.inner.error()242 }243}244Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 245why, one step back245impl DerefMut for Error {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 246–250why, one step back246 fn deref_mut(&mut self) -> &mut Self::Target {247 self.inner.error_mut()248 }249}250Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 251why, one step back251impl Debug for Error {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 252–254why, one step back252 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {253 writeln!(f, "{}", self.inner.error())?;254Touch up Debug impl for ErrorDavid Tolnaybefore adoption3cd7273
lines 255–256why, one step back255 let mut chain = self.chain().skip(1).enumerate();256 if let Some((n, error)) = chain.next() {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 257–258why, one step back257 writeln!(f, "\ncaused by:")?;258 writeln!(f, "\t{}: {}", n, error)?;Touch up Debug impl for ErrorDavid Tolnaybefore adoption3cd7273
line 259why, one step back259 for (n, error) in chain {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 260–263why, one step back260 writeln!(f, "\t{}: {}", n, error)?;261 }262 }263Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e
lines 264–277why, one step back264 #[cfg(backtrace)]265 {266 let backtrace = self.backtrace();267 match backtrace.status() {268 BacktraceStatus::Captured => {269 writeln!(f, "\n{}", backtrace)?;270 }271 BacktraceStatus::Disabled => {272 writeln!(273 f,274 "\nbacktrace disabled; run with RUST_LIB_BACKTRACE=1 environment variable to display a backtrace"275 )?;276 }277 _ => {}Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 278–284why, one step back278 }279 }280281 Ok(())282 }283}284Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 285why, one step back285impl Display for Error {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 286–290why, one step back286 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {287 write!(f, "{}", self.inner.error())288 }289}290Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
lines 291–292why, one step back291unsafe impl Send for Error {}292unsafe impl Sync for Error {}Rename exception module to errorDavid Tolnaybefore adoption2000930
line 293why, one step back293Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 294why, one step back294impl Drop for Error {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 295–301why, one step back295 fn drop(&mut self) {296 unsafe { ptr::drop_in_place(self.inner.error_mut()) }297 }298}299300// repr C to ensure that `E` remains in the final position301#[repr(C)]Rename InnerException to ErrorImplDavid Tolnaybefore adoption68dcc84
line 302why, one step back302struct ErrorImpl<E> {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 303–316why, one step back303 vtable: *const (),304 type_id: TypeId,305 backtrace: Option<Backtrace>,306 error: E,307}308309// repr C to ensure that transmuting from trait objects is safe310#[repr(C)]311struct TraitObject {312 data: *const (),313 vtable: *const (),314}315316#[repr(transparent)]Remove trait bounds from MessageError structDavid Tolnaybefore adoptioneac05d1
line 317why, one step back317struct MessageError<M>(M);Rename exception module to errorDavid Tolnaybefore adoption2000930
line 318why, one step back318Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 319–322why, one step back319impl<M> Debug for MessageError<M>320where321 M: Display + Debug,322{Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 323–327why, one step back323 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {324 Debug::fmt(&self.0, f)325 }326}327Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
lines 328–331why, one step back328impl<M> Display for MessageError<M>329where330 M: Display + Debug,331{Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 332–336why, one step back332 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {333 Display::fmt(&self.0, f)334 }335}336Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851
line 337why, one step back337impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {}Rename exception module to errorDavid Tolnaybefore adoption2000930
line 338why, one step back338Rename InnerException to ErrorImplDavid Tolnaybefore adoption68dcc84
line 339why, one step back339impl ErrorImpl<()> {Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 340why, one step back340 fn error(&self) -> &(dyn StdError + Send + Sync + 'static) {Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742
lines 341–346why, one step back341 let object = TraitObject {342 data: &self.error,343 vtable: self.vtable,344 };345346 unsafe { mem::transmute::<TraitObject, &(dyn StdError + Send + Sync + 'static)>(object) }Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 347–348why, one step back347 }348Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 349why, one step back349 fn error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742
lines 350–354why, one step back350 let object = TraitObject {351 data: &mut self.error,352 vtable: self.vtable,353 };354Rename exception module to errorDavid Tolnaybefore adoption2000930
line 355why, one step back355 unsafe {Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742
line 356why, one step back356 mem::transmute::<TraitObject, &mut (dyn StdError + Send + Sync + 'static)>(object)Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 357–360why, one step back357 }358 }359}360Rename Errors to ChainDavid Tolnaybefore adoptionf972193
lines 361–362why, one step back361/// Iterator of a chain of source errors.362pub struct Chain<'a> {Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 363why, one step back363 next: Option<&'a (dyn StdError + 'static)>,Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 364–365why, one step back364}365Rename Errors to ChainDavid Tolnaybefore adoptionf972193
line 366why, one step back366impl<'a> Iterator for Chain<'a> {Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190
line 367why, one step back367 type Item = &'a (dyn StdError + 'static);Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 368–380why, one step back368369 fn next(&mut self) -> Option<Self::Item> {370 let next = self.next.take()?;371 self.next = next.source();372 Some(next)373 }374}375376#[cfg(test)]377mod repr_correctness {378 use super::*;379 use std::marker::Unpin;380 use std::mem;Replace Mutex<bool> with AtomicBoolDavid Tolnaybefore adoption794ba39
lines 381–383why, one step back381 use std::sync::atomic::AtomicBool;382 use std::sync::atomic::Ordering::SeqCst;383 use std::sync::Arc;Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 384–385why, one step back384385 #[test]Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c
line 386why, one step back386 fn size_of_error() {Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc
line 387why, one step back387 assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 388–389why, one step back388 }389Simplify autotraits testDavid Tolnaybefore adoptionb0e25c5
lines 390–393why, one step back390 #[test]391 fn error_autotraits() {392 fn assert<E: Unpin + Send + Sync + 'static>() {}393 assert::<Error>();Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 394–396why, one step back394 }395396 #[test]Improve naming in Drop testDavid Tolnaybefore adoption04931ad
line 397why, one step back397 fn drop_works() {Rename exception module to errorDavid Tolnaybefore adoption2000930
line 398why, one step back398 #[derive(Debug)]Improve naming in Drop testDavid Tolnaybefore adoption04931ad
lines 399–405why, one step back399 struct DetectDrop {400 has_dropped: Arc<AtomicBool>,401 }402403 impl StdError for DetectDrop {}404405 impl Display for DetectDrop {Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 406–409why, one step back406 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {407 write!(f, "does something")408 }409 }Improve naming in Drop testDavid Tolnaybefore adoption04931ad
lines 410–411why, one step back410411 impl Drop for DetectDrop {Rename exception module to errorDavid Tolnaybefore adoption2000930
line 412why, one step back412 fn drop(&mut self) {Improve naming in Drop testDavid Tolnaybefore adoption04931ad
lines 413–414why, one step back413 let already_dropped = self.has_dropped.swap(true, SeqCst);414 assert!(!already_dropped);Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 415–417why, one step back415 }416 }417Replace Mutex<bool> with AtomicBoolDavid Tolnaybefore adoption794ba39
line 418why, one step back418 let has_dropped = Arc::new(AtomicBool::new(false));Rename exception module to errorDavid Tolnaybefore adoption2000930
line 419why, one step back419Improve naming in Drop testDavid Tolnaybefore adoption04931ad
lines 420–422why, one step back420 drop(Error::from(DetectDrop {421 has_dropped: has_dropped.clone(),422 }));Rename exception module to errorDavid Tolnaybefore adoption2000930
line 423why, one step back423Replace Mutex<bool> with AtomicBoolDavid Tolnaybefore adoption794ba39
line 424why, one step back424 assert!(has_dropped.load(SeqCst));Rename exception module to errorDavid Tolnaybefore adoption2000930
lines 425–426why, one step back425 }426}