Struct ferrisetw::parser::Parser

source ·
pub struct Parser<'schema, 'record> { /* private fields */ }
Expand description

Represents a Parser

This structure provides a way to parse an ETW event (= extract its properties). Because properties may have variable length (e.g. strings), a Parser is only suited to a single EventRecord

Example

let my_callback = |record: &EventRecord, schema_locator: &SchemaLocator| {
    let schema = schema_locator.event_schema(record).unwrap();
    let parser = Parser::create(record, &schema);

    // There are several ways to define the type requested for `try_parse`
    // It is possible to use type inference...
    let property1: Option<String> = parser.try_parse("PropertyName").ok();

    // ...or to use the turbofish operator
    match parser.try_parse::<u32>("OtherPropertyName") {
        Ok(_) => println!("OtherPropertyName is a valid u32"),
        Err(_) => println!("OtherPropertyName is invalid"),
    }
};

Implementations§

source§

impl<'schema, 'record> Parser<'schema, 'record>

source

pub fn create( event_record: &'record EventRecord, schema: &'schema Schema ) -> Self

Use the create function to create an instance of a Parser

Arguments
  • schema - The Schema from the ETW Event we want to parse
Example
let my_callback = |record: &EventRecord, schema_locator: &SchemaLocator| {
    let schema = schema_locator.event_schema(record).unwrap();
    let parser = Parser::create(record, &schema);
};
source

pub fn try_parse<T>(&self, name: &str) -> Result<T, ParserError>where Parser<'schema, 'record>: TryParse<T>,

Return a property from the event, or an error in case the parsing failed.

You must explicitly define T, the type you want to parse the property into.
In case this type is not compatible with the ETW type, ParserError::InvalidType is returned.

Auto Trait Implementations§

§

impl<'schema, 'record> RefUnwindSafe for Parser<'schema, 'record>

§

impl<'schema, 'record> !Send for Parser<'schema, 'record>

§

impl<'schema, 'record> !Sync for Parser<'schema, 'record>

§

impl<'schema, 'record> Unpin for Parser<'schema, 'record>

§

impl<'schema, 'record> UnwindSafe for Parser<'schema, 'record>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V