mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 15:06:30 +03:00
Write with_inner() in function of try_inner()
I guess this is a little neater. Note that this does change all the existing error logging to warning logging. I believe this is correct as these error log messages are really programming errors rather than errors which need to be show to the user. Also chose to make entire with_inner unsafe, there is little to be gained from hiding the unsafe as this is only used from unsafe functions in the first place.
This commit is contained in:
committed by
Floris Bruynooghe
parent
145fd8657f
commit
4bf2fc18e5
@@ -118,18 +118,17 @@ impl ContextWrapper {
|
||||
/// the appropriate return value for an error return since this
|
||||
/// differs for various functions on the FFI API: sometimes 0,
|
||||
/// NULL, an empty string etc.
|
||||
fn with_inner<T, F>(&self, ctxfn: F) -> Result<T, ()>
|
||||
///
|
||||
/// Prefer to use [ContextWrapper::try_inner], we might want to
|
||||
/// remove this function at some point to reduce the cognitive
|
||||
/// overload of having two functions which are too similar.
|
||||
unsafe fn with_inner<T, F>(&self, ctxfn: F) -> Result<T, ()>
|
||||
where
|
||||
F: FnOnce(&Context) -> T,
|
||||
{
|
||||
let guard = self.inner.read().unwrap();
|
||||
match guard.as_ref() {
|
||||
Some(ref ctx) => Ok(ctxfn(ctx)),
|
||||
None => {
|
||||
unsafe { self.error("context not open") };
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
self.try_inner(|ctx| Ok(ctxfn(ctx))).map_err(|err| {
|
||||
self.warning(&err.to_string());
|
||||
})
|
||||
}
|
||||
|
||||
/// Unlock the context and execute a closure with it.
|
||||
|
||||
Reference in New Issue
Block a user