]>
git.proxmox.com Git - rustc.git/blob - vendor/anyhow/tests/drop/mod.rs
ba2cc5ed68c4b93657b9b3156efd29ef2eafc3c7
1 #![allow(clippy::module_name_repetitions)]
3 use std
::error
::Error
as StdError
;
4 use std
::fmt
::{self, Display}
;
5 use std
::sync
::atomic
::AtomicBool
;
6 use std
::sync
::atomic
::Ordering
::SeqCst
;
11 atomic
: Arc
<AtomicBool
>,
15 pub fn new() -> Self {
17 atomic
: Arc
::new(AtomicBool
::new(false)),
21 pub fn get(&self) -> bool
{
22 self.atomic
.load(SeqCst
)
27 pub struct DetectDrop
{
32 pub fn new(has_dropped
: &Flag
) -> Self {
35 atomic
: Arc
::clone(&has_dropped
.atomic
),
41 impl StdError
for DetectDrop {}
43 impl Display
for DetectDrop
{
44 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
49 impl Drop
for DetectDrop
{
51 let already_dropped
= self.has_dropped
.atomic
.swap(true, SeqCst
);
52 assert
!(!already_dropped
);