aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/cancelation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src/cancelation.rs')
-rw-r--r--crates/ra_db/src/cancelation.rs49
1 files changed, 4 insertions, 45 deletions
diff --git a/crates/ra_db/src/cancelation.rs b/crates/ra_db/src/cancelation.rs
index 73444b015..56ce27bff 100644
--- a/crates/ra_db/src/cancelation.rs
+++ b/crates/ra_db/src/cancelation.rs
@@ -15,29 +15,17 @@
15//! any background processing (this bit is handled by salsa, see 15//! any background processing (this bit is handled by salsa, see
16//! `BaseDatabase::check_canceled` method). 16//! `BaseDatabase::check_canceled` method).
17 17
18use std::{
19 cmp,
20 hash::{Hash, Hasher},
21 sync::Arc,
22};
23
24use backtrace::Backtrace;
25use parking_lot::Mutex;
26
27/// An "error" signifing that the operation was canceled. 18/// An "error" signifing that the operation was canceled.
28#[derive(Clone)] 19#[derive(Clone, PartialEq, Eq, Hash)]
29pub struct Canceled { 20pub struct Canceled {
30 backtrace: Arc<Mutex<Backtrace>>, 21 _private: (),
31} 22}
32 23
33pub type Cancelable<T> = Result<T, Canceled>; 24pub type Cancelable<T> = Result<T, Canceled>;
34 25
35impl Canceled { 26impl Canceled {
36 pub(crate) fn new() -> Canceled { 27 pub(crate) fn new() -> Canceled {
37 let bt = Backtrace::new_unresolved(); 28 Canceled { _private: () }
38 Canceled {
39 backtrace: Arc::new(Mutex::new(bt)),
40 }
41 } 29 }
42} 30}
43 31
@@ -49,37 +37,8 @@ impl std::fmt::Display for Canceled {
49 37
50impl std::fmt::Debug for Canceled { 38impl std::fmt::Debug for Canceled {
51 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 39 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 let mut bt = self.backtrace.lock(); 40 write!(fmt, "Canceled")
53 let bt: &mut Backtrace = &mut *bt;
54 bt.resolve();
55 write!(fmt, "canceled at:\n{:?}", bt)
56 } 41 }
57} 42}
58 43
59impl std::error::Error for Canceled {} 44impl std::error::Error for Canceled {}
60
61impl PartialEq for Canceled {
62 fn eq(&self, _: &Canceled) -> bool {
63 true
64 }
65}
66
67impl Eq for Canceled {}
68
69impl Hash for Canceled {
70 fn hash<H: Hasher>(&self, hasher: &mut H) {
71 ().hash(hasher)
72 }
73}
74
75impl cmp::Ord for Canceled {
76 fn cmp(&self, _: &Canceled) -> cmp::Ordering {
77 cmp::Ordering::Equal
78 }
79}
80
81impl cmp::PartialOrd for Canceled {
82 fn partial_cmp(&self, other: &Canceled) -> Option<cmp::Ordering> {
83 Some(self.cmp(other))
84 }
85}