Skip to main content

EventQuery

Struct EventQuery 

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

Query result stream for batch iteration with reusable buffers.

Implementations§

Source§

impl EventQuery

Source

pub fn set_batch_timeout(&mut self, timeout: Duration)

Set timeout used by EvtNext for each batch retrieval call.

Source

pub fn with_event_data(self) -> Self

Enable EventData extraction (opt-in).

When enabled, events will have their data field populated with EventData key-value pairs. Common field names (e.g., “TargetUserName”, “ProcessId”) are automatically interned as Cow::Borrowed(&'static str) for zero-copy access.

Source

pub fn with_message(self) -> Self

Enable message formatting via EvtFormatMessage (opt-in).

When enabled, events will have their formatted_message field populated with the human-readable event message. Publisher metadata is cached for performance.

Source

pub fn set_render_format(&mut self, format: RenderFormat)

Set the rendering format for events (default: Values).

Source

pub fn next_batch(&mut self, out_events: &mut Vec<Event>) -> Result<usize>

Fetch next batch of events into output buffer.

Returns the count of events added to the buffer. When no more events are available, returns 0.

Source

pub fn next_batch_or_cancel( &mut self, out_events: &mut Vec<Event>, cancel: &Wait, ) -> Result<usize>

Fetch the next batch unless a cancel wait object is already signaled.

Returns 0 when cancellation is requested.

Source

pub fn next_batch_with_filter<F>( &mut self, out_events: &mut Vec<Event>, filter: F, ) -> Result<usize>
where F: Fn(&Event) -> bool,

Fetch next batch with filtering applied during enumeration.

The filter function is called for each parsed event; only events where the filter returns true are included.

Source

pub fn next_batch_raw_with_filter<T, F, P>( &mut self, out_events: &mut Vec<T>, converter: F, filter: P, ) -> Result<usize>
where F: FnMut(EVT_HANDLE) -> Result<T>, P: Fn(&T) -> bool,

Process events with a custom converter and filter for each raw event handle.

This allows custom event parsing without allocating the intermediate Event struct. The converter receives the raw EVT_HANDLE and returns a custom type T. The filter is applied after successful conversion.

§Example
use windows_erg::evt::{EventLog, types::{extract_event_id, extract_provider}};

#[derive(Debug)]
struct LightweightEvent {
    id: u32,
    provider: String,
}

let log = EventLog::open("Security")?;
let mut query = log.query_stream("*[System[EventID=4624]]")?;
let mut events = Vec::new();

query.next_batch_raw_with_filter(
    &mut events,
    |handle| {
        Ok(LightweightEvent {
            id: extract_event_id(handle)?,
            provider: extract_provider(handle)?,
        })
    },
    |event| event.id == 4624,
)?;
Source

pub fn next_batch_with_results( &mut self, out_events: &mut Vec<Result<Event, CorruptedEvent>>, ) -> Result<usize>

Fetch next batch with explicit corruption handling.

Returns both successfully parsed events (Ok) and corrupted events (Err) in a single vector, preserving event order.

§Example
use windows_erg::evt::EventLog;

let log = EventLog::open("System")?;
let mut query = log.query_stream("*")?;
let mut batch = Vec::new();

while query.next_batch_with_results(&mut batch)? > 0 {
    for result in &batch {
        match result {
            Ok(event) => println!("Event: {}", event.id),
            Err(corrupted) => println!("Corrupted: {}", corrupted.reason),
        }
    }
}

Trait Implementations§

Source§

impl Drop for EventQuery

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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<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.