Skip to content

Commit

Permalink
rename feature macros to macro-diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Nov 16, 2021
1 parent daefb3e commit 6dfdade
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -54,7 +54,7 @@ repository = "uuid-rs/uuid"
[features]
default = ["std"]
std = []
macros = ["uuid_macro"]
macro-diagnostics = ["uuid_macro"]

v1 = ["atomic"]
v3 = ["md-5"]
Expand Down
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -51,8 +51,10 @@ let my_uuid = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8")?;
assert_eq!(Some(Version::Random), my_uuid.get_version());
```

If you add the `macros` feature then you can parse UUIDs at compile time
instead of at runtime:
You can parse UUIDs at compile time instead of at runtime.

If you add the `macro-diagnostics` feature then you can see much better
error messages.

```rust
#[macro_use]
Expand All @@ -78,7 +80,7 @@ various pieces of functionality:
generate a `Uuid`.
* `v5` - adds the `Uuid::new_v5` function and the ability to create a V5
UUID based on the SHA1 hash of some data.
* `macros` - adds the `uuid!` macro that can parse UUIDs at compile time.
* `macro-diagnostics` - enhances the diagnostics of `uuid!` macro.
* `serde` - adds the ability to serialize and deserialize a `Uuid` using the
`serde` crate.
* `arbitrary` - adds an `Arbitrary` trait implementation to `Uuid`.
Expand Down
5 changes: 3 additions & 2 deletions examples/uuid_macro.rs
@@ -1,12 +1,13 @@
//! Using the `uuid!` macro.
//!
//! If you enable the `macros` feature you can use the `uuid!` macro.
//! `uuid!` will parse encoded UUIDs at compile time instead of at runtime.
//! If you've got a fixed UUID string handy then consider using `uuid!` instead
//! of `Uuid::parse_str` or `str::parse`.
//!
//! If you enable the `macro-diagnostics` feature, you can see much better
//! error messages.

#[test]
#[cfg(feature = "macros")]
fn parse_uuid_at_compile_time() {
use uuid::uuid;

Expand Down
4 changes: 2 additions & 2 deletions macros/src/lib.rs
@@ -1,11 +1,11 @@
//! Implementation details for the `uuid!` macro.
//!
//! This crate is not meant to be used directly. Instead,
//! you can use the `macros` feature of `uuid`:
//! you can use the `macro-diagnostics` feature of `uuid`:
//!
//! ```toml
//! [dependencies.uuid]
//! features = ["macros"]
//! features = ["macro-diagnostics"]
//! ```

use proc_macro::TokenStream;
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Expand Up @@ -70,7 +70,7 @@
//!
//! Other crate features can also be useful beyond the version support:
//!
//! * `macros` - adds the `uuid!` macro that can parse UUIDs from string literals at compile time.
//! * `macros` - enhances the diagnostics of `uuid!` macro.
//! * `serde` - adds the ability to serialize and deserialize a UUID using
//! `serde`.
//! * `arbitrary` - adds an `Arbitrary` trait implementation to `Uuid` for
Expand Down Expand Up @@ -243,8 +243,9 @@ mod external;

#[macro_use]
mod macros;

#[doc(hidden)]
#[cfg(feature = "macros")]
#[cfg(feature = "macro-diagnostics")]
pub extern crate uuid_macro;

use crate::std::convert;
Expand Down
12 changes: 6 additions & 6 deletions src/macros.rs
@@ -1,7 +1,7 @@
macro_rules! define_uuid_macro {
{$(#[$doc:meta])*} => {
$(#[$doc])*
#[cfg(feature = "macros")]
#[cfg(feature = "macro-diagnostics")]
#[macro_export]
macro_rules! uuid {
($uuid:literal) => {{
Expand All @@ -10,7 +10,7 @@ macro_rules! define_uuid_macro {
}

$(#[$doc])*
#[cfg(not(feature = "macros"))]
#[cfg(not(feature = "macro-diagnostics"))]
#[macro_export]
macro_rules! uuid {
($uuid:literal) => {{
Expand All @@ -20,7 +20,7 @@ macro_rules! define_uuid_macro {
// here triggers const_err
// const_panic requires 1.57
#[allow(unconditional_panic)]
let _ = ["invalid uuid representation"][1];
let _ = ["invalid uuid representation"][1];

loop {} // -> never type
}
Expand All @@ -31,7 +31,7 @@ macro_rules! define_uuid_macro {
}
}

define_uuid_macro!{
define_uuid_macro! {
/// Parse [`Uuid`][uuid::Uuid]s from string literals at compile time.
///
/// ## Usage
Expand Down Expand Up @@ -67,8 +67,8 @@ define_uuid_macro!{
/// let uuid: Uuid = uuid!("F9168C5E-ZEB2-4FAA-B6BF-329BF39FA1E4");
/// ```
///
/// Enable the feature `macros` to see the error messages below.
///
/// Enable the feature `macro-diagnostics` to see the error messages below.
///
/// Provides the following compilation error:
///
/// ```txt
Expand Down
2 changes: 1 addition & 1 deletion tests/macros.rs
@@ -1,4 +1,4 @@
#[cfg(feature = "macros")]
#[cfg(feature = "macro-diagnostics")]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
Expand Down

0 comments on commit 6dfdade

Please sign in to comment.