Skip to content

Commit

Permalink
Merge #218
Browse files Browse the repository at this point in the history
218: Add const Uuid::from_uuid_bytes r=kinggoesgaming a=mokeyish

<!--
    As we are working towards a stable version of uuid, we require that you 
    open an issue, before submitting a pull request. If the pull request is 
    imcomplete, prepend the Title with WIP: 
-->

**I'm submitting a  const Uuid::from_uuid_bytes for creating const uuid value.**  [ref uuid_macro](uuid-rs/uuid_macro#1)
  - [ ] bug fix
  - [x] feature enhancement
  - [ ] deprecation or removal
  - [ ] refactor

# Description
<!-- Provide a summary of your changes in the Title above -->

# Motivation
<!-- Why is this change required -->

# Tests
<!-- How are these changes tested? -->

# Related Issue(s)
<!-- 
    As noted above, we require an issue for every PR. Please link to the issue
    here
-->


Co-authored-by: MOKEYISH <[email protected]>
Co-authored-by: YISH <[email protected]>
  • Loading branch information
3 people committed May 11, 2018
2 parents 99cc741 + e2475e1 commit 1950606
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cargo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/config
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ serde_test = "1.0.19"

[features]
default = ["std"]
nightly = []
std = []
use_std = ["std"] # Compatibility shim for 0.5 and earlier
v1 = []
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
)]
#![deny(warnings)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(const_fn))]


#[macro_use]
extern crate cfg_if;
Expand Down Expand Up @@ -714,10 +716,16 @@ impl Uuid {
///
/// let uuid = Uuid::from_uuid_bytes(bytes);
/// ```
#[cfg(not(feature = "nightly"))]
pub fn from_uuid_bytes(b: UuidBytes) -> Uuid {
Uuid { bytes: b }
}

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

/// Creates a v4 Uuid from random bytes (e.g. bytes supplied from `Rand` crate)
///
/// # Examples
Expand Down

0 comments on commit 1950606

Please sign in to comment.