Skip to content

Commit

Permalink
Add doc comments to every UniqueId method
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Jul 21, 2023
1 parent 2fb0a08 commit ad14884
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rbx_types/src/unique_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub struct UniqueId {
static INDEX: AtomicU32 = AtomicU32::new(0);

impl UniqueId {
/// Returns a non-unique `UniqueId` that has every field set to `0`.
/// This value may appear multiple times in a Roblox file safely.
pub fn non_unique() -> Self {
Self {
index: 0,
Expand All @@ -54,6 +56,8 @@ impl UniqueId {
}
}

/// Returns a new `UniqueId` with each component set to the passed
/// values.
pub fn new(index: u32, time: u32, random: i64) -> Self {
Self {
index,
Expand All @@ -62,6 +66,7 @@ impl UniqueId {
}
}

/// Returns a new UniqueId.
pub fn now() -> Result<Self, UniqueIdError> {
let time = SystemTime::now()
.duration_since(*EPOCH)
Expand All @@ -76,24 +81,38 @@ impl UniqueId {
})
}

/// Returns whether this `UniqueId` represents a value that **must** be
/// unique across all Instances in a Roblox file.
pub fn is_unique(&self) -> bool {
// Note that because only one field needs to be non-zero, we use
// || here
self.time != 0 || self.index != 0 || self.random != 0
}

/// Returns whether this `UniqueId` represents the non-unique
/// `UniqueId` value.
pub fn is_non_unique(&self) -> bool {
!self.is_unique()
}

/// The 'time' portion of the UniqueId. This is the number of seconds since
/// 1 January 2021.
///
/// Pending system time errors, this value will always be above `0`.
pub fn time(&self) -> u32 {
self.time
}

/// The 'index' portion of the UniqueId.
///
/// This value may be any number in the range `[0, u32::MAX]`.
pub fn index(&self) -> u32 {
self.index
}

/// The 'random' portion of the `UniqueId`.
///
/// This value may be any number in the range `[0, i64::MAX]`.
pub fn random(&self) -> i64 {
self.random
}
Expand Down

0 comments on commit ad14884

Please sign in to comment.