Struct guid_create::GUID
source · pub struct GUID { /* private fields */ }
Expand description
A GUID backed by 16 byte array.
Implementations§
source§impl GUID
impl GUID
sourcepub fn build_from_components(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Self
pub fn build_from_components(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Self
Construct a GUID
from components.
let guid = guid_create::GUID::build_from_components(
0x87935CDE,
0x7094,
0x4C2B,
&[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
);
assert_eq!(guid.data1(), 0x87935CDE);
assert_eq!(guid.data2(), 0x7094);
assert_eq!(guid.data3(), 0x4C2B);
assert_eq!(guid.data4(), [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]);
assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261");
sourcepub fn build_from_slice(data: &[u8; 16]) -> Self
pub fn build_from_slice(data: &[u8; 16]) -> Self
Construct a GUID
from 16 bytes.
let guid = guid_create::GUID::build_from_slice(&[
0x87, 0x93, 0x5C, 0xDE, 0x70, 0x94, 0x4C, 0x2B, 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D,
0xD2, 0x61,
]);
assert_eq!(guid.data1(), 0x87935CDE);
assert_eq!(guid.data2(), 0x7094);
assert_eq!(guid.data3(), 0x4C2B);
assert_eq!(
guid.data4(),
[0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61]
);
assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261");
sourcepub fn parse(guid: &str) -> Result<Self, ParseError>
pub fn parse(guid: &str) -> Result<Self, ParseError>
Construct a GUID
from a string.
let guid = guid_create::GUID::parse("87935CDE-7094-4C2B-A0F4-DD7D512DD261").unwrap();
assert_eq!(guid.data1(), 0x87935CDE);
assert_eq!(guid.data2(), 0x7094);
assert_eq!(guid.data3(), 0x4C2B);
assert_eq!(guid.data4(), [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]);
assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261");
sourcepub fn data1(&self) -> u32
pub fn data1(&self) -> u32
The first four bytes.
extern crate guid_create;
let guid = guid_create::GUID::build_from_components(
500,
600,
700,
&[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
);
assert_eq!(guid.data1(), 500);
sourcepub fn data2(&self) -> u16
pub fn data2(&self) -> u16
Bytes 5 and 6.
extern crate guid_create;
let guid = guid_create::GUID::build_from_components(
500,
600,
700,
&[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
);
assert_eq!(guid.data2(), 600);
sourcepub fn data3(&self) -> u16
pub fn data3(&self) -> u16
Bytes 7 and 8.
extern crate guid_create;
let guid = guid_create::GUID::build_from_components(
500,
600,
700,
&[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
);
assert_eq!(guid.data3(), 700);
sourcepub fn data4(&self) -> [u8; 8]
pub fn data4(&self) -> [u8; 8]
The last eight bytes.
extern crate guid_create;
let guid = guid_create::GUID::build_from_components(
500,
600,
700,
&[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
);
assert_eq!(
guid.data4(),
[0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61]
);
sourcepub fn as_winapi_guid(&self) -> WinGuid
pub fn as_winapi_guid(&self) -> WinGuid
Convert the GUID
to a winapi
GUID
Only present on windows targets
extern crate guid_create;
let guid = guid_create::GUID::build_from_components(
0x87935CDE,
0x7094,
0x4C2B,
&[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
);
let win = guid.as_winapi_guid();
assert_eq!(win.Data1, 0x87935CDE);
assert_eq!(win.Data2, 0x7094);
assert_eq!(win.Data3, 0x4C2B);
assert_eq!(win.Data4, [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]);
sourcepub fn from_winapi_guid(guid: WinGuid) -> Self
pub fn from_winapi_guid(guid: WinGuid) -> Self
Convert a winapi
GUID to a GUID
Only present on windows targets
extern crate guid_create;
extern crate winapi;
let win = winapi::shared::guiddef::GUID {
Data1: 0x87935CDE,
Data2: 0x7094,
Data3: 0x4C2B,
Data4: [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]
};
let guid = guid_create::GUID::from_winapi_guid(win);
assert_eq!(guid.data1(), 0x87935CDE);
assert_eq!(guid.data2(), 0x7094);
assert_eq!(guid.data3(), 0x4C2B);
assert_eq!(guid.data4(), [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]);