Struct tracelogging::Guid
source · #[repr(C)]pub struct Guid { /* private fields */ }
Expand description
Implementations§
source§impl Guid
impl Guid
sourcepub fn new() -> Self
pub fn new() -> Self
Generates a unique GUID using UuidCreate. Note: For a zeroed GUID, use Guid::zero().
let g = Guid::new();
sourcepub fn from_name(event_provider_name: &str) -> Self
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));
sourcepub const fn from_fields(
data1: u32,
data2: u16,
data3: u16,
data4: [u8; 8]
) -> Self
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]));
sourcepub const fn from_bytes_be(bytes_be: &[u8; 16]) -> Self
pub const fn from_bytes_be(bytes_be: &[u8; 16]) -> Self
Creates a GUID from bytes in RFC (big-endian) 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]) -> Self
pub const fn from_bytes_le(bytes_le: &[u8; 16]) -> Self
Creates a GUID from bytes in Windows (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) -> Self
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));
sourcepub fn try_parse(value: &str) -> Option<Self>
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());
sourcepub fn try_parse_ascii(value: &[u8]) -> Option<Self>
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());
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 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 tracelogging::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 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 Ord for Guid
impl Ord for Guid
source§impl PartialEq<Guid> for Guid
impl PartialEq<Guid> for Guid
source§impl PartialOrd<Guid> for Guid
impl PartialOrd<Guid> for Guid
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more