Skip to main content

ScopedGuard

Struct ScopedGuard 

Source
pub struct ScopedGuard<K: Key, F>
where F: FnOnce(&WideEvent<K>) + Send + 'static,
{ /* private fields */ }
Expand description

RAII guard that owns a WideEvent and emits it on drop.

The guard starts a timer on creation. On drop, it sets the duration field (via Key::DURATION_PATH) to the elapsed milliseconds, sets the timestamp field (via Key::TIMESTAMP_PATH) to the current time as an RFC 3339 string in the guard’s timezone, and calls the emit function with a reference to the event.

Implements Deref / DerefMut to WideEvent so you can call add, add_path, inc, etc. directly on the guard.

The wide_log! macro generates a WideLogGuard that wraps this guard and manages the thread-local / task-local pointer. Users typically interact with WideLogGuard, not ScopedGuard directly.

Implementations§

Source§

impl<K: Key, F> ScopedGuard<K, F>
where F: FnOnce(&WideEvent<K>) + Send + 'static,

Source

pub fn new_with_tz(emit_fn: F, tz: Tz) -> Self

Creates a new guard with the given emit function and timezone.

The timezone is used to format the timestamp set on drop.

Methods from Deref<Target = WideEvent<K>>§

Source

pub fn add_path<V: Into<Value<K>>>(&mut self, path: &[K], value: V)

Set a value at a nested path. Traverses/creates intermediate objects.

Source

pub fn inc_path(&mut self, path: &[K])

Source

pub fn dec_path(&mut self, path: &[K])

Source

pub fn add_n_path(&mut self, path: &[K], n: i64)

Source

pub fn append_log_entry(&mut self, level: &'static str, message: &str)

Source

pub fn append_log_entry_static( &mut self, level: &'static str, message: &'static str, )

Append a log entry with a &'static str message — zero-copy.

Source

pub fn to_json(&self) -> Result<String, Error>

Source

pub fn serialize_to<W: Write>(&self, w: &mut W) -> Result<(), Error>

Serialize directly to a writer, bypassing serde entirely. Uses itoa/ryu for zero-allocation number formatting.

Trait Implementations§

Source§

impl<K: Key, F> Deref for ScopedGuard<K, F>
where F: FnOnce(&WideEvent<K>) + Send + 'static,

Source§

type Target = WideEvent<K>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &WideEvent<K>

Dereferences the value.
Source§

impl<K: Key, F> DerefMut for ScopedGuard<K, F>
where F: FnOnce(&WideEvent<K>) + Send + 'static,

Source§

fn deref_mut(&mut self) -> &mut WideEvent<K>

Mutably dereferences the value.
Source§

impl<K: Key, F> Drop for ScopedGuard<K, F>
where F: FnOnce(&WideEvent<K>) + Send + 'static,

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

Auto Trait Implementations§

§

impl<K, F> Freeze for ScopedGuard<K, F>
where F: Freeze,

§

impl<K, F> RefUnwindSafe for ScopedGuard<K, F>

§

impl<K, F> Send for ScopedGuard<K, F>
where K: Send,

§

impl<K, F> Sync for ScopedGuard<K, F>
where F: Sync, K: Sync,

§

impl<K, F> Unpin for ScopedGuard<K, F>
where F: Unpin, K: Unpin,

§

impl<K, F> UnsafeUnpin for ScopedGuard<K, F>
where F: UnsafeUnpin,

§

impl<K, F> UnwindSafe for ScopedGuard<K, F>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.