Struct ofdb_entities::nonce::Nonce

source ·
pub struct Nonce(/* private fields */);

Implementations§

source§

impl Nonce

source

pub const STR_LEN: usize = 32usize

source

pub fn new() -> Self

Methods from Deref<Target = Uuid>§

source

pub fn as_hyphenated(&self) -> &Hyphenated

Get a borrowed Hyphenated formatter.

source

pub fn as_simple(&self) -> &Simple

Get a borrowed Simple formatter.

source

pub fn as_urn(&self) -> &Urn

Get a borrowed Urn formatter.

source

pub fn as_braced(&self) -> &Braced

Get a borrowed Braced formatter.

source

pub const NAMESPACE_DNS: Uuid = _

source

pub const NAMESPACE_OID: Uuid = _

source

pub const NAMESPACE_URL: Uuid = _

source

pub const NAMESPACE_X500: Uuid = _

source

pub fn get_variant(&self) -> Variant

Returns the variant of the UUID structure.

This determines the interpretation of the structure of the UUID. This method simply reads the value of the variant byte. It doesn’t validate the rest of the UUID as conforming to that variant.

Examples

Basic usage:

let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?;

assert_eq!(Variant::RFC4122, my_uuid.get_variant());
References
source

pub fn get_version_num(&self) -> usize

Returns the version number of the UUID.

This represents the algorithm used to generate the value. This method is the future-proof alternative to Uuid::get_version.

Examples

Basic usage:

let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?;

assert_eq!(3, my_uuid.get_version_num());
References
source

pub fn get_version(&self) -> Option<Version>

Returns the version of the UUID.

This represents the algorithm used to generate the value. If the version field doesn’t contain a recognized version then None is returned. If you’re trying to read the version for a future extension you can also use Uuid::get_version_num to unconditionally return a number. Future extensions may start to return Some once they’re standardized and supported.

Examples

Basic usage:

let my_uuid = Uuid::parse_str("02f09a3f-1624-3b1d-8409-44eff7708208")?;

assert_eq!(Some(Version::Md5), my_uuid.get_version());
References
source

pub fn as_fields(&self) -> (u32, u16, u16, &[u8; 8])

Returns the four field values of the UUID.

These values can be passed to the Uuid::from_fields method to get the original Uuid back.

  • The first field value represents the first group of (eight) hex digits, taken as a big-endian u32 value. For V1 UUIDs, this field represents the low 32 bits of the timestamp.
  • The second field value represents the second group of (four) hex digits, taken as a big-endian u16 value. For V1 UUIDs, this field represents the middle 16 bits of the timestamp.
  • The third field value represents the third group of (four) hex digits, taken as a big-endian u16 value. The 4 most significant bits give the UUID version, and for V1 UUIDs, the last 12 bits represent the high 12 bits of the timestamp.
  • The last field value represents the last two groups of four and twelve hex digits, taken in order. The first 1-3 bits of this indicate the UUID variant, and for V1 UUIDs, the next 13-15 bits indicate the clock sequence and the last 48 bits indicate the node ID.
Examples
let uuid = Uuid::nil();

assert_eq!(uuid.as_fields(), (0, 0, 0, &[0u8; 8]));

let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.as_fields(),
    (
        0xa1a2a3a4,
        0xb1b2,
        0xc1c2,
        &[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8],
    )
);
source

pub fn to_fields_le(&self) -> (u32, u16, u16, &[u8; 8])

Returns the four field values of the UUID in little-endian order.

The bytes in the returned integer fields will be converted from big-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

Examples
use uuid::Uuid;

let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.to_fields_le(),
    (
        0xa4a3a2a1,
        0xb2b1,
        0xc2c1,
        &[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8],
    )
);
source

pub fn as_u128(&self) -> u128

Returns a 128bit value containing the value.

The bytes in the UUID will be packed directly into a u128.

Examples
let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.as_u128(),
    0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8,
);
source

pub fn to_u128_le(&self) -> u128

Returns a 128bit little-endian value containing the value.

The bytes in the u128 will be flipped to convert into big-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

Note that this will produce a different result than Uuid::to_fields_le, because the entire UUID is reversed, rather than reversing the individual fields in-place.

Examples
let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.to_u128_le(),
    0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1,
);
source

pub fn as_u64_pair(&self) -> (u64, u64)

Returns two 64bit values containing the value.

The bytes in the UUID will be split into two u64. The first u64 represents the 64 most significant bits, the second one represents the 64 least significant.

Examples
let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;
assert_eq!(
    uuid.as_u64_pair(),
    (0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8),
);
source

pub fn as_bytes(&self) -> &[u8; 16]

Returns a slice of 16 octets containing the value.

This method borrows the underlying byte value of the UUID.

Examples
let bytes1 = [
    0xa1, 0xa2, 0xa3, 0xa4,
    0xb1, 0xb2,
    0xc1, 0xc2,
    0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];
let uuid1 = Uuid::from_bytes_ref(&bytes1);

let bytes2 = uuid1.as_bytes();
let uuid2 = Uuid::from_bytes_ref(bytes2);

assert_eq!(uuid1, uuid2);

assert!(std::ptr::eq(
    uuid2 as *const Uuid as *const u8,
    &bytes1 as *const [u8; 16] as *const u8,
));
source

pub fn to_bytes_le(&self) -> [u8; 16]

Returns the bytes of the UUID in little-endian order.

The bytes will be flipped to convert into little-endian order. This is based on the endianness of the UUID, rather than the target environment so bytes will be flipped on both big and little endian machines.

Examples
use uuid::Uuid;

let uuid = Uuid::parse_str("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8")?;

assert_eq!(
    uuid.to_bytes_le(),
    ([
        0xa4, 0xa3, 0xa2, 0xa1, 0xb2, 0xb1, 0xc2, 0xc1, 0xd1, 0xd2,
        0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8
    ])
);
source

pub fn is_nil(&self) -> bool

Tests if the UUID is nil (all zeros).

source

pub fn is_max(&self) -> bool

Tests if the UUID is max (all ones).

source

pub fn get_timestamp(&self) -> Option<Timestamp>

If the UUID is the correct version (v1, v6, or v7) this will return the timestamp and counter portion parsed from a V1 UUID.

Returns None if the supplied UUID is not V1.

The V1 timestamp format defined in RFC4122 specifies a 60-bit integer representing the number of 100-nanosecond intervals since 00:00:00.00, 15 Oct 1582.

Timestamp offers several options for converting the raw RFC4122 value into more commonly-used formats, such as a unix timestamp.

Roundtripping

This method is unlikely to roundtrip a timestamp in a UUID due to the way UUIDs encode timestamps. The timestamp returned from this method will be truncated to 100ns precision for version 1 and 6 UUIDs, and to millisecond precision for version 7 UUIDs.

Trait Implementations§

source§

impl AsRef<Uuid> for Nonce

source§

fn as_ref(&self) -> &Uuid

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Nonce

source§

fn clone(&self) -> Nonce

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 Nonce

source§

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

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

impl Default for Nonce

source§

fn default() -> Nonce

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

impl Deref for Nonce

§

type Target = Uuid

The resulting type after dereferencing.
source§

fn deref(&self) -> &Uuid

Dereferences the value.
source§

impl Display for Nonce

source§

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

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

impl From<Nonce> for Uuid

source§

fn from(from: Nonce) -> Self

Converts to this type from the input type.
source§

impl From<Uuid> for Nonce

source§

fn from(from: Uuid) -> Self

Converts to this type from the input type.
source§

impl FromStr for Nonce

§

type Err = NonceParseError

The associated error which can be returned from parsing.
source§

fn from_str(nonce_str: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Ord for Nonce

source§

fn cmp(&self, other: &Nonce) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Nonce

source§

fn eq(&self, other: &Nonce) -> 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 PartialOrd for Nonce

source§

fn partial_cmp(&self, other: &Nonce) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Nonce

source§

impl Eq for Nonce

source§

impl StructuralEq for Nonce

source§

impl StructuralPartialEq for Nonce

Auto Trait Implementations§

§

impl RefUnwindSafe for Nonce

§

impl Send for Nonce

§

impl Sync for Nonce

§

impl Unpin for Nonce

§

impl UnwindSafe for Nonce

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where U: Into<T>,

§

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>,

§

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

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

§

fn vzip(self) -> V