blob: d1fc29a3e4265786826baa61d6970ff4e1cb80c9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use crate::{Database, Transaction};
use anyhow::Result;
pub trait DatabaseReturnExt: Database {
fn transaction_ret<T>(
&self,
mut t: impl FnMut(&mut dyn Transaction) -> Result<T>,
) -> Result<T> {
let mut ret = None;
self.transaction(&mut |x| {
ret = Some(t(x)?);
Ok(())
})?;
Ok(ret.unwrap())
}
}
impl<D: Database + ?Sized> DatabaseReturnExt for D {}
|