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
impl UUID
Sourcepub fn to_hyphenated_string(&self) -> String
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");
Sourcepub fn get_time(&self) -> Option<u64>
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());
Sourcepub fn is_uprotocol_uuid(&self) -> bool
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());
Trait Implementations§
Source§impl FromStr for UUID
impl FromStr for UUID
Source§fn from_str(uuid_str: &str) -> Result<Self, Self::Err>
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§impl Message for UUID
impl Message for UUID
Source§fn is_initialized(&self) -> bool
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<()>
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
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<()>
fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_>, ) -> Result<()>
Write message to the stream. Read more
Source§fn special_fields(&self) -> &SpecialFields
fn special_fields(&self) -> &SpecialFields
Special fields (unknown fields and cached size).
Source§fn mut_special_fields(&mut self) -> &mut SpecialFields
fn mut_special_fields(&mut self) -> &mut SpecialFields
Special fields (unknown fields and cached size).
Source§fn default_instance() -> &'static UUID
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>
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self, Error>
Parse message from stream.
Source§fn cached_size(&self) -> u32
fn cached_size(&self) -> u32
Get size previously computed by
compute_size
. Read moreSource§fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<(), Error>
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>
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>
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>
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>
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_tokio_bytes(bytes: &Bytes) -> Result<Self, Error>
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>
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>
fn write_to_writer(&self, w: &mut dyn Write) -> Result<(), Error>
Write the message to the writer.
Source§fn write_length_delimited_to_writer(
&self,
w: &mut dyn Write,
) -> Result<(), Error>
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>
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
fn unknown_fields(&self) -> &UnknownFields
Get a reference to unknown fields.
Source§fn mut_unknown_fields(&mut self) -> &mut UnknownFields
fn mut_unknown_fields(&mut self) -> &mut UnknownFields
Get a mutable reference to unknown fields.
Source§impl MessageFull for UUID
impl MessageFull for UUID
Source§fn descriptor() -> MessageDescriptor
fn descriptor() -> MessageDescriptor
Get message descriptor for message type. Read more
Source§fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool
fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool
Reflective equality. Read more
Source§impl ProtobufValue for UUID
impl ProtobufValue for UUID
Source§type RuntimeType = RuntimeTypeMessage<UUID>
type RuntimeType = RuntimeTypeMessage<UUID>
Actual implementation of type properties.
impl Eq for UUID
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<M> MessageDyn for Mwhere
M: MessageFull,
impl<M> MessageDyn for Mwhere
M: MessageFull,
Source§fn descriptor_dyn(&self) -> MessageDescriptor
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>
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>
fn write_to_with_cached_sizes_dyn( &self, os: &mut CodedOutputStream<'_>, ) -> Result<(), Error>
Write the message.
Source§fn compute_size_dyn(&self) -> u64
fn compute_size_dyn(&self) -> u64
Compute (and cache) the message size.
Source§fn is_initialized_dyn(&self) -> bool
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
fn special_fields_dyn(&self) -> &SpecialFields
Get a reference to special fields.
Source§fn mut_special_fields_dyn(&mut self) -> &mut SpecialFields
fn mut_special_fields_dyn(&mut self) -> &mut SpecialFields
Get a mutable reference to special fields.