pub struct Guid(/* private fields */);Expand description
UUID with big-endian in-memory representation.
Implementations§
Source§impl Guid
impl Guid
Sourcepub fn from_name(event_provider_name: &str) -> Guid
pub fn from_name(event_provider_name: &str) -> Guid
Returns a GUID generated from a case-insensitive hash of the specified trace provider name. The hash uses the same algorithm as many Windows tracing 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));Sourcepub const fn from_fields(
data1: u32,
data2: u16,
data3: u16,
data4: [u8; 8],
) -> Guid
pub const fn from_fields( data1: u32, data2: u16, data3: u16, data4: [u8; 8], ) -> Guid
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]));Sourcepub const fn from_bytes_be(bytes_be: &[u8; 16]) -> Guid
pub const fn from_bytes_be(bytes_be: &[u8; 16]) -> Guid
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]));Sourcepub const fn from_bytes_le(bytes_le: &[u8; 16]) -> Guid
pub const fn from_bytes_le(bytes_le: &[u8; 16]) -> Guid
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]));Sourcepub const fn from_u128(value: &u128) -> Guid
pub const fn from_u128(value: &u128) -> Guid
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));Sourcepub fn try_parse(value: &str) -> Option<Guid>
pub fn try_parse(value: &str) -> Option<Guid>
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());Sourcepub fn try_parse_ascii(value: &[u8]) -> Option<Guid>
pub fn try_parse_ascii(value: &[u8]) -> Option<Guid>
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());Sourcepub const fn to_fields(&self) -> (u32, u16, u16, [u8; 8])
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]));Sourcepub const fn as_bytes_raw(&self) -> &[u8; 16]
pub const fn as_bytes_raw(&self) -> &[u8; 16]
Returns this implementation’s in-memory byte representation.
assert_eq!(
*Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).as_bytes_raw(),
[0xa3, 0xa2, 0xa1, 0xa0, 0xb1, 0xb0, 0xc1, 0xc0, 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]);Sourcepub const fn to_bytes_be(&self) -> [u8; 16]
pub const fn to_bytes_be(&self) -> [u8; 16]
Returns the bytes of the GUID in RFC byte order (big-endian).
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]);Sourcepub const fn to_bytes_le(&self) -> [u8; 16]
pub const fn to_bytes_le(&self) -> [u8; 16]
Returns the bytes of the GUID in Windows byte order (little-endian).
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]);Sourcepub const fn to_u128(&self) -> u128
pub const fn to_u128(&self) -> u128
Returns the GUID as a u128 value.
use eventheader_types::Guid;
assert_eq!(
Guid::from_fields(0xa3a2a1a0, 0xb1b0, 0xc1c0, [0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xd0]).to_u128(),
0xa3a2a1a0_b1b0_c1c0_d7d6d5d4d3d2d1d0);Sourcepub const fn to_utf8_bytes(&self) -> [u8; 36]
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 eventheader_types::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");