tor_persist/
fs_mistrust_error_ext.rs1use paste::paste;
4
5use tor_error::ErrorKind;
6
7use ErrorKind as EK;
8
9fn mistrust_error_kind(e: &fs_mistrust::Error, access_failed: ErrorKind) -> ErrorKind {
11 if e.is_bad_permission() {
12 EK::FsPermissions
13 } else {
14 access_failed
15 }
16}
17
18macro_rules! accesses { {
29 $( $([ $prefix:ident ])? $kind:ident, $description:tt; )*
30} => { paste!{
31
32 pub trait FsMistrustErrorExt: Sealed {
34 $(
35
36 #[doc = concat!("The error kind if we were trying to access", $description)]
37 fn [<$kind _error_kind>](&self) -> ErrorKind;
38 )*
39 }
40
41 impl FsMistrustErrorExt for fs_mistrust::Error {
42 $(
43 fn [<$kind _error_kind>](&self) -> tor_error::ErrorKind {
44 mistrust_error_kind(self, EK::[<$($prefix)? $kind:camel AccessFailed>])
45 }
46 )*
47 }
48
49} } }
50
51pub trait Sealed {}
53impl Sealed for fs_mistrust::Error {}
54
55accesses! {
56 cache, "a cache directory";
57 [Persistent] state, "a persistent state directory";
58 keystore, "a keystore";
59}