Struct tracelogging::Guid

source ·
#[repr(C)]
pub struct Guid { /* private fields */ }
Expand description

GUID (UUID). with host-endian in-memory representation (as expected by the ETW APIs).

Implementations§

source§

impl Guid

source

pub const fn zero() -> Self

Returns a zeroed GUID, i.e. GUID_NULL.

source

pub fn from_name(event_provider_name: &str) -> Self

Returns a GUID generated from a case-insensitive hash of the specified trace provider name. The hash uses the same algorithm as many other ETW tools and APIs. Given the same name, it will always generate the same GUID.

assert_eq!(
   Guid::from_name("MyProvider"),
   Guid::from_u128(&0xb3864c38_4273_58c5_545b_8b3608343471));
source

pub const fn from_fields( data1: u32, data2: u16, data3: u16, data4: [u8; 8] ) -> Self

Creates a GUID from field values.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::from_bytes_be(&[0xa3, 0xa2, 0xa1, 0xa0, 0xb1, 0xb0, 0xc1, 0xc0, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]));
source

pub const fn from_bytes_be(bytes_be: &[u8; 16]) -> Self

Creates a GUID from bytes in big-endian (RFC) byte order.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::from_bytes_be(&[0xa3, 0xa2, 0xa1, 0xa0, 0xb1, 0xb0, 0xc1, 0xc0, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]));
source

pub const fn from_bytes_le(bytes_le: &[u8; 16]) -> Self

Creates a GUID from bytes in little-endian byte order.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::from_bytes_le(&[0xa0, 0xa1, 0xa2, 0xa3, 0xb0, 0xb1, 0xc0, 0xc1, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]));
source

pub const fn from_u128(value: &u128) -> Self

Creates a GUID from a u128 value.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::from_u128(&0xa3a2a1a0_b1b0_c1c0_d7d6d5d4d3d2d1d0));
source

pub fn try_parse(value: &str) -> Option<Self>

Creates a GUID from a string with optional {} and optional ‘-’. Returns None if GUID could not be parsed from the input.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::try_parse("{a3a2a1a0-b1b0-c1c0-d7d6-d5d4d3d2d1d0}").unwrap());
assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::try_parse("a3a2a1a0-b1b0-c1c0-d7d6-d5d4d3d2d1d0").unwrap());
assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::try_parse("a3a2a1a0b1b0c1c0d7d6d5d4d3d2d1d0").unwrap());
source

pub fn try_parse_ascii(value: &[u8]) -> Option<Self>

Creates a GUID from a string with optional {} and optional ‘-’. Returns None if GUID could not be parsed from the input.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::try_parse_ascii(b"{a3a2a1a0-b1b0-c1c0-d7d6-d5d4d3d2d1d0}").unwrap());
assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::try_parse_ascii(b"a3a2a1a0-b1b0-c1c0-d7d6-d5d4d3d2d1d0").unwrap());
assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]),
    Guid::try_parse_ascii(b"a3a2a1a0b1b0c1c0d7d6d5d4d3d2d1d0").unwrap());
source

pub const fn to_fields(&self) -> (u32, u16, u16, [u8; 8])

Returns the field values of the GUID as a tuple.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).to_fields(),
    (0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]));
source

pub const fn as_bytes_raw(&self) -> &[u8; 16]

Returns this implementation’s in-memory byte representation.

source

pub const fn to_bytes_be(&self) -> [u8; 16]

Returns the bytes of the GUID in big-endian (RFC) byte order.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).to_bytes_be(),
    [0xa3, 0xa2, 0xa1, 0xa0, 0xb1, 0xb0, 0xc1, 0xc0, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]);
source

pub const fn to_bytes_le(&self) -> [u8; 16]

Returns the bytes of the GUID in little-endian byte order.

assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).to_bytes_le(),
    [0xa0, 0xa1, 0xa2, 0xa3, 0xb0, 0xb1, 0xc0, 0xc1, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]);
source

pub const fn to_u128(&self) -> u128

Returns the GUID as a u128 value.

use tracelogging::Guid;
assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).to_u128(),
    0xa3a2a1a0_b1b0_c1c0_d7d6d5d4d3d2d1d0);
source

pub const fn to_utf8_bytes(&self) -> [u8; 36]

Convert GUID to utf8 string bytes. To get a &str, use: str::from_utf8(&guid.to_utf8_bytes()).unwrap().

use tracelogging::Guid;
assert_eq!(
    Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).to_utf8_bytes(),
    *b"a3a2a1a0-b1b0-c1c0-d7d6-d5d4d3d2d1d0");

Trait Implementations§

source§

impl Borrow<[u8; 16]> for Guid

source§

fn borrow(&self) -> &[u8; 16]

Returns this implementation’s in-memory byte representation.

source§

impl Clone for Guid

source§

fn clone(&self) -> Guid

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Guid

source§

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

Format the GUID, e.g. “a3a2a1a0-b1b0-c1c0-d7d6-d5d4d3d2d1d0”.

source§

impl Default for Guid

source§

fn default() -> Guid

Returns the “default value” for a type. Read more
source§

impl Hash for Guid

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Guid

source§

fn cmp(&self, other: &Guid) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Guid> for Guid

source§

fn eq(&self, other: &Guid) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Guid> for Guid

source§

fn partial_cmp(&self, other: &Guid) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Guid

source§

impl Eq for Guid

source§

impl StructuralEq for Guid

source§

impl StructuralPartialEq for Guid

Auto Trait Implementations§

§

impl RefUnwindSafe for Guid

§

impl Send for Guid

§

impl Sync for Guid

§

impl Unpin for Guid

§

impl UnwindSafe for Guid

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.