GUID

Struct GUID 

Source
pub struct GUID { /* private fields */ }
Expand description

A GUID backed by 16 byte array.

Implementations§

Source§

impl GUID

Source

pub const 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");
Source

pub const 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");
Source

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");
Source

pub fn rand() -> GUID

Generates a new GUID with 16 random bytes.

Source

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);
Source

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);
Source

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);
Source

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]
);

Trait Implementations§

Source§

impl Clone for GUID

Source§

fn clone(&self) -> GUID

Returns a duplicate 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

Formats the value using the given formatter. Read more
Source§

impl Default for GUID

Source§

fn default() -> GUID

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

impl<'de> Deserialize<'de> for GUID

Source§

fn deserialize<D>(deserializer: D) -> Result<GUID, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for GUID

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<CGuid> for GUID

Source§

fn from(item: CGuid) -> Self

Converts to this type from the input type.
Source§

impl From<GUID> for CGuid

Source§

fn from(item: GUID) -> Self

Converts to this type from the input type.
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 PartialEq for GUID

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for GUID

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Zeroable for GUID

Source§

fn zeroed() -> Self

Source§

impl Copy for GUID

Source§

impl Eq for GUID

Source§

impl Pod for GUID

Source§

impl StructuralPartialEq for GUID

Auto Trait Implementations§

§

impl Freeze for GUID

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> NoUninit for T
where T: Pod,