Construct a GUID
from components.
extern crate guid_create;
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");
Construct a GUID
from 16 bytes.
extern crate guid_create;
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");
Construct a GUID
from a string.
Leverages guid-parser
for the parsing.
extern crate guid_create;
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");
Generates a new GUID with 16 random bytes.
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);
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);
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);
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]
);
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 ]);
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 ]);