Struct UUID

Source
pub struct UUID {
    pub msb: u64,
    pub lsb: u64,
    pub special_fields: SpecialFields,
}

Fields§

§msb: u64§lsb: u64§special_fields: SpecialFields

Implementations§

Source§

impl UUID

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 up_rust::UUID;

let uuid = UUID::build();
assert!(uuid.is_uprotocol_uuid());
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 { msb, lsb, ..Default::default() };
assert_eq!(uuid.to_hyphenated_string(), "00000000-0001-7000-8010-101010101a1a");
Source

pub fn get_time(&self) -> Option<u64>

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

§Returns

The number of milliseconds since UNIX EPOCH if this UUID is a uProtocol UUID, or Option::None otherwise.

§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 { msb, lsb, ..Default::default() }.get_time();
assert_eq!(creation_time.unwrap(), 0x018D548EA8E0_u64);

// timestamp = 1, (invalid) ver = 0b1100
let msb = 0x000000000001C000u64;
// variant = 0b10
let lsb = 0x8000000000000000u64;
let creation_time = UUID { msb, lsb, ..Default::default() }.get_time();
assert!(creation_time.is_none());
Source

pub fn is_uprotocol_uuid(&self) -> bool

Checks if this is a valid uProtocol UUID.

§Returns

true if this UUID meets the formal requirements defined by the uProtocol spec.

§Examples
use up_rust::UUID;

// timestamp = 1, ver = 0b0111
let msb = 0x0000000000017000u64;
// variant = 0b10
let lsb = 0x8000000000000000u64;
assert!(UUID { msb, lsb, ..Default::default() }.is_uprotocol_uuid());

// timestamp = 1, (invalid) ver = 0b1100
let msb = 0x000000000001C000u64;
// variant = 0b10
let lsb = 0x8000000000000000u64;
assert!(!UUID { msb, lsb, ..Default::default() }.is_uprotocol_uuid());

// timestamp = 1, ver = 0b0111
let msb = 0x0000000000017000u64;
// (invalid) variant = 0b01
let lsb = 0x4000000000000000u64;
assert!(!UUID { msb, lsb, ..Default::default() }.is_uprotocol_uuid());
Source§

impl UUID

Source

pub fn new() -> UUID

Trait Implementations§

Source§

impl Clone for UUID

Source§

fn clone(&self) -> UUID

Returns a duplicate of the value. Read more
1.0.0 · Source§

const 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<'a> Default for &'a UUID

Source§

fn default() -> &'a UUID

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

impl Default for UUID

Source§

fn default() -> UUID

Returns the “default value” for a type. 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 String

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());
let uuid = parsing_attempt.unwrap();
assert!(uuid.is_uprotocol_uuid());
assert_eq!(uuid.msb, 0x0000000000017000_u64);
assert_eq!(uuid.lsb, 0x8010101010101a1a_u64);

// 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 Message for UUID

Source§

const NAME: &'static str = "UUID"

Message name as specified in .proto file. Read more
Source§

fn is_initialized(&self) -> bool

True iff all required fields are initialized. Always returns true for protobuf 3.
Source§

fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>

Update this message object with fields read from given stream.
Source§

fn compute_size(&self) -> u64

Compute and cache size of this message and all nested messages. Read more
Source§

fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_>, ) -> Result<()>

Write message to the stream. Read more
Source§

fn special_fields(&self) -> &SpecialFields

Special fields (unknown fields and cached size).
Source§

fn mut_special_fields(&mut self) -> &mut SpecialFields

Special fields (unknown fields and cached size).
Source§

fn new() -> UUID

Create an empty message object. Read more
Source§

fn clear(&mut self)

Reset all fields.
Source§

fn default_instance() -> &'static UUID

Return a pointer to default immutable message with static lifetime. Read more
Source§

fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self, Error>

Parse message from stream.
Source§

fn cached_size(&self) -> u32

Get size previously computed by compute_size. Read more
Source§

fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<(), Error>

Write the message to the stream. Read more
Source§

fn write_length_delimited_to( &self, os: &mut CodedOutputStream<'_>, ) -> Result<(), Error>

Write the message to the stream prepending the message with message length encoded as varint.
Source§

fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<(), Error>

Write the message to the vec, prepend the message with message length encoded as varint.
Source§

fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<(), Error>

Update this message object with fields read from given stream.
Source§

fn parse_from_reader(reader: &mut dyn Read) -> Result<Self, Error>

Parse message from reader. Parse stops on EOF or when error encountered.
Source§

fn parse_from_bytes(bytes: &[u8]) -> Result<Self, Error>

Parse message from byte array.
Source§

fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self, Error>

Parse message from Bytes object. Resulting message may share references to the passed bytes object.
Source§

fn check_initialized(&self) -> Result<(), Error>

Check if all required fields of this object are initialized.
Source§

fn write_to_writer(&self, w: &mut dyn Write) -> Result<(), Error>

Write the message to the writer.
Source§

fn write_to_vec(&self, v: &mut Vec<u8>) -> Result<(), Error>

Write the message to bytes vec.
Source§

fn write_to_bytes(&self) -> Result<Vec<u8>, Error>

Write the message to bytes vec. Read more
Source§

fn write_length_delimited_to_writer( &self, w: &mut dyn Write, ) -> Result<(), Error>

Write the message to the writer, prepend the message with message length encoded as varint.
Source§

fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>, Error>

Write the message to the bytes vec, prepend the message with message length encoded as varint.
Source§

fn unknown_fields(&self) -> &UnknownFields

Get a reference to unknown fields.
Source§

fn mut_unknown_fields(&mut self) -> &mut UnknownFields

Get a mutable reference to unknown fields.
Source§

impl MessageFull for UUID

Source§

fn descriptor() -> MessageDescriptor

Get message descriptor for message type. Read more
Source§

fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool

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

const 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 ProtobufValue for UUID

Source§

type RuntimeType = RuntimeTypeMessage<UUID>

Actual implementation of type properties.
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
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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.

Source§

impl<T> Instrument for T

Source§

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

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

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<M> MessageDyn for M
where M: MessageFull,

Source§

fn descriptor_dyn(&self) -> MessageDescriptor

Message descriptor for this message, used for reflection.
Source§

fn merge_from_dyn(&mut self, is: &mut CodedInputStream<'_>) -> Result<(), Error>

Update this message fields with contents of given stream.
Source§

fn write_to_with_cached_sizes_dyn( &self, os: &mut CodedOutputStream<'_>, ) -> Result<(), Error>

Write the message.
Source§

fn compute_size_dyn(&self) -> u64

Compute (and cache) the message size.
Source§

fn is_initialized_dyn(&self) -> bool

True iff all required fields are initialized. Always returns true for protobuf 3.
Source§

fn special_fields_dyn(&self) -> &SpecialFields

Get a reference to special fields.
Source§

fn mut_special_fields_dyn(&mut self) -> &mut SpecialFields

Get a mutable reference to special fields.
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> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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