Skip to main content

diesel/
util.rs

1/// Treats tuples as a list which can be appended to. e.g.
2/// `(a,).tuple_append(b) == (a, b)`
3pub trait TupleAppend<T> {
4    type Output;
5
6    fn tuple_append(self, right: T) -> Self::Output;
7}
8
9pub trait TupleSize {
10    const SIZE: usize;
11}
12
13#[cfg(not(feature = "std"))]
14pub(crate) mod std_compat {
15    pub(crate) type Entry<'a, K, V> =
16        hashbrown::hash_map::Entry<'a, K, V, hashbrown::DefaultHashBuilder>;
17    pub(crate) use hashbrown::HashMap;
18
19    pub(crate) fn catch_unwind<R>(f: impl FnOnce() -> R) -> Result<R, ()> {
20        Ok(f())
21    }
22    pub(crate) fn panicking() -> bool {
23        false
24    }
25
26    pub(crate) fn abort() -> ! {
27        struct DropBomb;
28
29        impl Drop for DropBomb {
30            fn drop(&mut self) {
31                panic!("Abort");
32            }
33        }
34
35        let _guard = DropBomb;
36
37        panic!("Abort");
38    }
39}
40
41#[cfg(feature = "std")]
42pub(crate) mod std_compat {
43    pub(crate) use std::collections::HashMap;
44    pub(crate) use std::collections::hash_map::Entry;
45    #[cfg(feature = "__sqlite-shared")]
46    pub(crate) use std::panic::catch_unwind;
47    #[cfg(feature = "__sqlite-shared")]
48    pub(crate) use std::process::abort;
49    #[cfg(feature = "__sqlite-shared")]
50    pub(crate) use std::thread::panicking;
51}