Preview of the proposed up-rust native-frame-model branch (up-rust b6b99c6d, up-spec f0e9b17) — not released documentation. branch · write-up

Struct UUID

Source
#[repr(C)]
pub struct UUID { /* private fields */ }
Expand description

A uProtocol UUIDv7 message identifier (RFC 9562 layout).

Implementations§

Source§

impl UUID

Source

pub fn from_bytes(bytes: &[u8; 16]) -> Result<Self, UuidConversionError>

Creates a new UUID from a byte array.

§Arguments

bytes - the byte array

§Returns

a uProtocol UUID with the given timestamp and random values.

§Errors

Returns an error if the given bytes contain an invalid version and/or variant identifier.

Source

pub fn from_u64_pair(msb: u64, lsb: u64) -> Result<Self, UuidConversionError>

Creates a new UUID from a high/low value pair.

§Arguments

msb - the most significant 8 bytes lsb - the least significant 8 bytes

§Returns

a uProtocol UUID with the given timestamp and random values.

§Errors

Returns an error if the given bytes contain an invalid version and/or variant identifier.

Source

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

Gets this UUID as a pair of 64 bit integers.

§Returns

A tuple of the most significant and least significant 8 bytes, i.e. the inverse of UUID::from_u64_pair.

Source

pub fn build() -> UUID

Creates a new UUID that can be used for uProtocol messages.

§Panics

if the system clock is set to an instant before the UNIX Epoch.

§Examples
use std::time::SystemTime;
use up_rust::UUID;

let uuid = UUID::build();
assert!(uuid.time() <= SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH)
    .expect("current system time is set to a point in time before UNIX Epoch")
    .as_millis() as u64);
Source

pub fn to_hyphenated_string(&self) -> String

Serializes this UUID to a hyphenated string as defined by RFC 4122, Section 3 using lower case characters.

§Examples
use up_rust::UUID;

// timestamp = 1, ver = 0b0111
let msb = 0x0000000000017000_u64;
// variant = 0b10, random = 0x0010101010101a1a
let lsb = 0x8010101010101a1a_u64;
let uuid = UUID::from_u64_pair(msb, lsb).unwrap();
assert_eq!(uuid.to_hyphenated_string(), "00000000-0001-7000-8010-101010101a1a");
Source

pub fn time(&self) -> u64

Returns the point in time that this UUID has been created at.

§Returns

The number of milliseconds since UNIX EPOCH.

§Examples
use up_rust::UUID;

// timestamp = 0x018D548EA8E0 (Monday, 29 January 2024, 9:30:52 AM GMT)
// ver = 0b0111
let msb = 0x018D548EA8E07000u64;
// variant = 0b10
let lsb = 0x8000000000000000u64;
let creation_time = UUID::from_u64_pair(msb, lsb).unwrap().time();
assert_eq!(creation_time, 0x018D548EA8E0_u64);
Source

pub fn get_time(&self) -> u64

👎Deprecated since 0.11.0: renamed to time

Deprecated alias for Self::time.

Trait Implementations§

Source§

impl Clone for UUID

Source§

fn clone(&self) -> UUID

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 UUID

Source§

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

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

impl Display for UUID

Source§

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

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

impl From<&UUID> for String

Source§

fn from(value: &UUID) -> Self

Converts to this type from the input type.
Source§

impl From<&UUID> for Vec<u8>

Source§

fn from(value: &UUID) -> Self

Serializes this UUID to a byte vector.

§Returns

a byte vector containing the 16 bytes of this UUID in big-endian order.

§Examples
use up_rust::UUID;

// timestamp = 1, ver = 0b0111
let msb = 0x0000000000017000_u64;
// variant = 0b10, random = 0x0010101010101a1a
let lsb = 0x8010101010101a1a_u64;
let uuid = UUID::from_u64_pair(msb, lsb).unwrap();
let bytes: Vec<u8> = uuid.into();
assert_eq!(bytes, vec![
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x70, 0x00,
    0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1a, 0x1a,
]);
Source§

impl From<UUID> for String

Source§

fn from(value: UUID) -> Self

Converts to this type from the input type.
Source§

impl From<UUID> for Vec<u8>

Source§

fn from(value: UUID) -> Self

Converts to this type from the input type.
Source§

impl FromStr for UUID

Source§

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

Parses a string into a UUID.

§Returns

a uProtocol UUID based on the bytes encoded in the string.

§Errors

Returns an error

  • if the given string does not represent a UUID as defined by RFC 4122, Section 3, or
  • if the bytes encoded in the string contain an invalid version and/or variant identifier.
§Examples
use up_rust::UUID;

// parsing a valid uProtocol UUID succeeds
let parsing_attempt = "00000000-0001-7000-8010-101010101a1A".parse::<UUID>();
assert!(parsing_attempt.is_ok());

// parsing an invalid UUID fails
assert!("a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8"
    .parse::<UUID>()
    .is_err());

// parsing a string that is not a UUID fails
assert!("this-is-not-a-UUID"
    .parse::<UUID>()
    .is_err());
Source§

type Err = UuidConversionError

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

impl Hash for UUID

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 UUID

Source§

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

Source§

fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>

Parses an instance of this type from the given protobuf bytes. Read more
Source§

fn parse_from_packed_protobuf_bytes( proto: &[u8], ) -> Result<Self, SerializationError>

Parses an instance of this type from the given packed protobuf bytes. Read more
Source§

fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>

Serializes this instance to protobuf bytes. Read more
Source§

fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>

Serializes this instance to packed protobuf bytes. Read more
Source§

impl TryFrom<Vec<u8>> for UUID

Source§

fn try_from(value: Vec<u8>) -> Result<Self, Self::Error>

Creates a UUID from a byte vector.

§Arguments

value - the byte vector

§Returns

a uProtocol UUID with the given timestamp and random values.

§Errors

Returns an error

  • if the given vector does not have a length of 16 bytes, or
  • if the given bytes contain an invalid version and/or variant identifier.
§Examples
use up_rust::UUID;

// timestamp = 1, ver = 0b0111, variant = 0b10
let bytes: Vec<u8> = vec![
    0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x70, 0x00,
    0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
let conversion_attempt = UUID::try_from(bytes);
assert!(conversion_attempt.is_ok());
let uuid = conversion_attempt.unwrap();
assert_eq!(uuid.time(), 0x1_u64);
Source§

type Error = UuidConversionError

The type returned in the event of a conversion error.
Source§

impl Eq for UUID

Source§

impl StructuralPartialEq for UUID

Auto Trait Implementations§

§

impl Freeze for UUID

§

impl RefUnwindSafe for UUID

§

impl Send for UUID

§

impl Sync for UUID

§

impl Unpin for UUID

§

impl UnwindSafe for UUID

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

type Output = T

Should always be Self
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<TCore> UWithNativePrefixWire for TCore

Source§

fn into_native_prefix_wire_transport<W>( self, wire: W, ) -> UWireTransport<TCore, W, NativePrefixFrameMetadataCodec>
where W: UWire,

Wraps this core with an external or custom selected wire using canonical metadata.
Source§

fn into_protobuf_transport( self, ) -> UWireTransport<TCore, ProtobufWire, NativePrefixFrameMetadataCodec>

Wraps this core with the Protocol Buffers selected-wire profile.
Source§

fn into_stable_container_transport( self, ) -> UWireTransport<TCore, StableContainerWireFormat, NativePrefixFrameMetadataCodec>

Wraps this core with the stable-container selected-wire profile.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more