Skip to main content

AutoLogGuard

Struct AutoLogGuard 

Source
pub struct AutoLogGuard { /* private fields */ }
Expand description

Owned, non-Clone guard that emits a lifecycle log entry when dropped.

Created via OperationContext::with_auto_log. Unlike OperationContext — which is a plain, Clone data value — this guard owns the context and performs the suc! / fail! / cancel! log write exactly once, on drop.

§Why a separate, non-Clone type?

A drop-time side effect must not be duplicated by cloning; otherwise attaching an armed context to an error would log the same failure twice (or defer the log to the error’s drop). Keeping the guard non-Clone while the data type stays Clone makes “attach as data” (err.with_context(&guard)) free of side effects.

§Example

use orion_error::OperationContext;

let ctx = OperationContext::doing("renew").with_field("gateway_id", "gw-1");
let data = ctx.clone(); // pure data copy, safe to attach to an error
let _guard = ctx.with_auto_log(); // logs once, on drop
let _ = data;

Implementations§

Source§

impl AutoLogGuard

Source

pub fn with_field<K, V>(self, key: K, val: V) -> Self
where K: Into<String>, V: Display,

Builder-style field addition while keeping the guard alive.

Source

pub fn with_meta<K, V>(self, key: K, value: V) -> Self
where K: Into<String>, V: Into<MetadataValue>,

Builder-style metadata addition while keeping the guard alive.

Source

pub fn with_mod_path<S: Into<String>>(self, path: S) -> Self

Builder-style module-path override while keeping the guard alive.

Source

pub fn mark_success(&mut self)

Explicitly mark the guarded operation as successful (suc!).

Source

pub fn mark_failure(&mut self)

Keep the failure result (the default), logging fail! on drop.

Source

pub fn cancel(&mut self)

Mark the guarded operation as cancelled (cancel!).

Source

pub fn into_context(self) -> OperationContext

Disarm the guard and return the owned, pure-data OperationContext without emitting a log entry.

Methods from Deref<Target = OperationContext>§

Source

pub fn context(&self) -> &CallContext

Source

pub fn result(&self) -> &OperationResult

Source

pub fn mod_path(&self) -> &String

Source

pub fn action(&self) -> &Option<String>

Source

pub fn locator(&self) -> &Option<String>

Source

pub fn path(&self) -> &[String]

Source

pub fn metadata(&self) -> &ErrorMetadata

Source

pub fn with_doing<S: Into<String>>(&mut self, action: S)

Source

pub fn with_at<S: Into<String>>(&mut self, locator: S)

Source

pub fn set_target<S: Into<String>>(&mut self, target: S)

Alias: set the target resource/operation name. The first call establishes the root target; subsequent calls only append to the path.

Source

pub fn path_string(&self) -> Option<String>

Source

pub fn record_field<K, V>(&mut self, key: K, val: V)
where K: Into<String>, V: Display,

Record a human-readable key-value pair into the context stack.

The entry will appear in the error’s Display output. For typed metadata hidden from console output, use [record_meta()] instead.

Prefer with_field for chained construction. record_field is for when you already have a mutable reference.

Source

pub fn record<K, V>(&mut self, key: K, val: V)
where K: Into<String>, V: Display,

Source

pub fn record_meta<K, V>(&mut self, key: K, value: V)
where K: Into<String>, V: Into<MetadataValue>,

Record typed metadata that is not included in Display output.

Use this for structured fields intended for serialization, snapshots, or API responses. For user-visible context entries, use [record_field()].

Prefer with_meta for chained construction. record_meta is for when you already have a mutable reference.

Source

pub fn mark_suc(&mut self)

Source

pub fn mark_cancel(&mut self)

Source

pub fn mark_fail(&mut self)

Source

pub fn scope(&mut self) -> OperationScope<'_>

Create a scope guard, defaulting to failure state. Requires explicit mark_success(), mark_cancel(), or mark_fail().

Source

pub fn scoped_success(&mut self) -> OperationScope<'_>

Create a scope guard that automatically marks success on drop.

Source

pub fn info<S: AsRef<str>>(&self, message: S)

Source

pub fn debug<S: AsRef<str>>(&self, message: S)

Source

pub fn warn<S: AsRef<str>>(&self, message: S)

Source

pub fn error<S: AsRef<str>>(&self, message: S)

Source

pub fn trace<S: AsRef<str>>(&self, message: S)

Source

pub fn log_info<S: AsRef<str>>(&self, message: S)

Alias for documentation consistency (calls the same-named method above).

Source

pub fn log_debug<S: AsRef<str>>(&self, message: S)

Source

pub fn log_warn<S: AsRef<str>>(&self, message: S)

Source

pub fn log_error<S: AsRef<str>>(&self, message: S)

Source

pub fn log_trace<S: AsRef<str>>(&self, message: S)

Trait Implementations§

Source§

impl Debug for AutoLogGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for AutoLogGuard

Source§

type Target = OperationContext

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for AutoLogGuard

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Display for AutoLogGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for AutoLogGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl From<&AutoLogGuard> for OperationContext

Attach an armed AutoLogGuard’s context to an error as pure data.

Taking the guard by shared reference deliberately copies only the data; the guard keeps ownership and remains the single owner responsible for the drop-time log entry. There is intentionally no From<AutoLogGuard> (by value): moving the guard into an error would defer/repeat its log.

§

fn from(value: &AutoLogGuard) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.