1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-08-01 04:38:31 +00:00
continuwuity/src/core/result/debug_inspect.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
983 B
Rust
Raw Normal View History

use super::Result;
/// Inspect Result values with release-mode elision.
pub trait DebugInspect<T, E> {
/// Inspects an Err contained value in debug-mode. In release-mode closure F
/// is elided.
#[must_use]
fn debug_inspect_err<F: FnOnce(&E)>(self, f: F) -> Self;
/// Inspects an Ok contained value in debug-mode. In release-mode closure F
/// is elided.
#[must_use]
fn debug_inspect<F: FnOnce(&T)>(self, f: F) -> Self;
}
#[cfg(debug_assertions)]
impl<T, E> DebugInspect<T, E> for Result<T, E> {
#[inline]
fn debug_inspect<F>(self, f: F) -> Self
where
F: FnOnce(&T),
{
self.inspect(f)
}
#[inline]
fn debug_inspect_err<F>(self, f: F) -> Self
where
F: FnOnce(&E),
{
self.inspect_err(f)
}
}
#[cfg(not(debug_assertions))]
impl<T, E> DebugInspect<T, E> for Result<T, E> {
#[inline]
fn debug_inspect<F>(self, _: F) -> Self
where
F: FnOnce(&T),
{
self
}
#[inline]
fn debug_inspect_err<F>(self, _: F) -> Self
where
F: FnOnce(&E),
{
self
}
}