1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#[macro_export]
macro_rules! opt_update {
    ($conn:ident, $query:expr => ($self:expr, $constraint:expr)) => {
        {
            if let Some(x) = $self.as_ref() {
                ::sqlx::query!($query, x, $constraint)
                    .execute(&mut *$conn)
                    .await?;
            }
        }
    };
    ($conn:ident, $query:expr => ($self:expr, $constraint:expr), $($tail:tt)+) => {
        {
            crate::opt_update!($conn, $query => ($self, $constraint));
            crate::opt_update!($conn, $($tail)*);
        }
    }
}

#[cfg(not(debug_assertions))]
pub fn ffpath(bin: impl AsRef<str>) -> &'static str {
    let mut path = std::env::current_exe().expect("Failed to grab path to the `dim` binary.");
    path.pop(); // remove the dim bin to get the dir of `dim`
    path.push(bin.as_ref());

    Box::leak(path.to_string_lossy().to_string().into_boxed_str())
}

#[cfg(debug_assertions)]
pub fn ffpath(bin: impl AsRef<str>) -> &'static str {
    Box::leak(bin.as_ref().to_string().into_boxed_str())
}