Skip to content

Commit

Permalink
Merge branch 'master' into serde
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan-DPC authored May 22, 2018
2 parents 176f2cd + 6b5774b commit ffcc774
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,31 @@ impl Uuid {
/// assert_eq!(uuid.hyphenated().to_string(),
/// "00000000-0000-0000-0000-000000000000");
/// ```
#[cfg(feature = "const-fn")]
pub const fn nil() -> Self {
Uuid { bytes: [0; 16] }
}

/// The 'nil UUID'.
///
/// The nil UUID is special form of UUID that is specified to have all
/// 128 bits set to zero, as defined in [IETF RFC 4122 Section 4.1.7][RFC].
///
/// [RFC]: https://tools.ietf.org/html/rfc4122.html#section-4.1.7
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use uuid::Uuid;
///
/// let uuid = Uuid::nil();
///
/// assert_eq!(uuid.hyphenated().to_string(),
/// "00000000-0000-0000-0000-000000000000");
/// ```
#[cfg(not(feature = "const-fn"))]
pub fn nil() -> Uuid {
Uuid { bytes: [0; 16] }
}
Expand Down Expand Up @@ -725,13 +750,13 @@ impl Uuid {
/// let uuid = Uuid::from_uuid_bytes(bytes);
/// ```
#[cfg(not(feature = "const-fn"))]
pub fn from_uuid_bytes(b: UuidBytes) -> Uuid {
Uuid { bytes: b }
pub fn from_uuid_bytes(bytes: UuidBytes) -> Uuid {
Uuid { bytes }
}

#[cfg(feature = "const-fn")]
pub const fn from_uuid_bytes(b: UuidBytes) -> Uuid {
Uuid { bytes: b }
pub const fn from_uuid_bytes(bytes: UuidBytes) -> Uuid {
Uuid { bytes }
}

/// Creates a v4 Uuid from random bytes (e.g. bytes supplied from `Rand` crate)
Expand Down Expand Up @@ -887,6 +912,27 @@ impl Uuid {
/// &[147, 109, 160, 31, 154, 189, 77, 157,
/// 128, 199, 2, 175, 133, 200, 34, 168]);
/// ```
#[cfg(feature = "const-fn")]
pub const fn as_bytes(&self) -> &[u8; 16] {
&self.bytes
}

/// Returns an array of 16 octets containing the UUID data.
///
/// # Examples
///
/// ```
/// use uuid::Uuid;
///
/// let uuid = Uuid::nil();
/// assert_eq!(uuid.as_bytes(), &[0; 16]);
///
/// let uuid = Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8").unwrap();
/// assert_eq!(uuid.as_bytes(),
/// &[147, 109, 160, 31, 154, 189, 77, 157,
/// 128, 199, 2, 175, 133, 200, 34, 168]);
/// ```
#[cfg(not(feature = "const-fn"))]
pub fn as_bytes(&self) -> &[u8; 16] {
&self.bytes
}
Expand Down

0 comments on commit ffcc774

Please sign in to comment.