Struct guid_create::GUID

source ·
pub struct GUID { /* private fields */ }
Expand description

A GUID backed by 16 byte array.

Implementations§

source§

impl GUID

source

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

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");
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 copy 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 Display for GUID

source§

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

Formats the value using the given formatter. Read more
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<GUID> for GUID

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for GUID

source§

impl Eq for GUID

source§

impl StructuralEq for GUID

source§

impl StructuralPartialEq for GUID

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V